Ajax is now quite popular technology, Ajax is not only to send messages to the server side, but more importantly, there is no reload of the page.
If the page simply use JS to create, to write a large number of code, and not intuitive.
In asp.net, we can actually create user-defined controls that return user-defined HTML code through AJAX requests.
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");//加载用户定义控件
TextBox txtBox1 = ctrl.FindControl("TextBox1") as TextBox;//获得id为“TextBox1”的控件
txtBox1.Text = "测试"; //给控件初始化
string result;
try
{
ctrl.RenderControl(htmlWriter);
}
catch { }
finally
{
htmlWriter.Flush();
result=build.ToString();
}
return result;//返回控件的HTML代码
}
htmlWriter.Flush();