Ajax is now a very popular technology. Ajax not only wants to send messages on the server side, but also does not need to reload the page.
If the page is simply created using js, it requires a lot of code and is not intuitive.
In asp.net, we can create user-defined controls and return the HTML code of user-defined controls through Ajax requests.
Code
Public static string RangerUsControl (string controlName) {StringBuilder build = new StringBuilder (); HtmlTextWriter htmlWriter = new HtmlTextWriter (new StringWriter (build); UserControl uc = new UserControl (); control ctrl = uc. loadControl (controlName + ". ascx "); // loads user-defined controls
TextBox txtBox1 = ctrl. FindControl ("TextBox1") as TextBox; // obtain the control txtBox1.Text = "test" with the id "TextBox1"; // initialize the control
String result; try {ctrl. renderControl (htmlWriter);} catch {} finally {htmlWriter. flush (); result = build. toString ();} return result; // return the HTML code of the control}
HtmlWriter. Flush ();