I would like to add an ASP:label and ASP:textbox control to a page through Javascript.
<asp:Label ID="lblone" runat="server"></asp:Label>
if i want to write this syntax or want to add this label on page using innerHTML then want can be the way….
I want to add it on button click event… and the ID should be appended by 1 and the next time 1+1
Does it need to be an ASP .NET control or could it just be normal HTML?
If you want an ASP .NET control these, by design, are rendered on the server so there would either need to add the controls by using one of the following approaches:
1) Synchronous PostBack (normal postback)
2) Async PostBack (javascript postback which doesn’t refresh the page visually but still does a postback)
3) Traditional AJAX
You’ve probably already tried the Sync PostBack since you’re mentioning that you want to do this in Javascript. So that leaves Async PostBack or traditional AJAX.
The Async PostBack is the easiest because you just need to wrap everything in an
UpdatePanelTreat this like a normal postback and in the codebehind add whatever control you want to the placeholder on button click.
The third approach (adding via AJAX) is a little too much to describe here but basically you would use AJAX to make a request to a web service that you would set up on the server and then you would need to “render” the control on the server (each control has a RenderControl function…you would need to use this to get the resulting HTML) and use the resulting HTML to send back as a response of the web server…sorry if that’s a little vague. Like I said the traditional AJAX approach requires more description than I can get into here.
Good luck.