Click here to Skip to main content
15,616,746 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
Hello to every body. I am new for creating html dynamically. My requirement is that, i created one aspx page, In that I have some content and one button. When i click the button one html page need to generate with my content. Can anyone help me to generate html pages dynamically.


Thanks in advance!
Posted
Updated 14-Feb-12 1:40am
v2
Comments
Varun Sareen 14-Feb-12 7:41am    
edited for: content makeover

1 solution

Double click the button in the designer, and it will generate an event handler for you. Then put your code to add the dymanic html in the handler.

If you are worried about how to insert the HTML then one method is to add an ASP.NET Literal control to the postion in the page you want to generate the HTML, then set its Text property to the HTML you have generated.

You could also override to the page's Render method an use it to write the HTML to the client. You'd need to check the page is under postback (and, optionally, that the button has been clicked depending upon your needs). The other thing to do is not to call the base Render method, as is sometimes done when overriding it.

Finally, I'd suggest you think about whether your strategy is appropiate (it could be-but it doesn't harm to examine what you are doing). For example it is normally better to dynamically add ASP.NET controls to the page, or create a control that renders the html you want. If you need really fine control over the HTML across most of your application MVC3 might be a better choice.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900