How to generate a full ASP.Net Webform via Server Controls?
I need to make a full asp.net webform with Server Control. I Wonder how to do this? There is a class called Page in .Net but I don't know how to work with it. A Page or WebForm must have a URL so from other pages can be开发者_StackOverflow accessible. Who knows this?
Your problem is to generate your page without using aspx, am I right ? If you want your page to be accessible from your WebServer, you will need the .aspx file, even if you completely generate your page by code.
To create your page, you create a class who inherits from the Page class, and you add your server controls to it.
public class TestCodePage : Page
{
public TestCodePage()
{
HtmlForm form = new HtmlForm();
LiteralControl l = new LiteralControl("I write a text in my form");
form.Controls.Add(l);
this.Controls.Add(form);
}
}
In order to have an url for this page, you just need to create an aspx page with this content :
<%@ Page Inherits="MyWebApp.TestCodePage" %>
精彩评论