If the page is simply created using js, a lot of code needs to be written, and it is not intuitive.
In asp.net, we can actually create user-defined controls and return user-defined control 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();
For more articles about Asp.net dynamically loading user-defined controls and converting them into HTML code, please pay attention to the PHP Chinese website!