我想使用cs代码在aspx页面中使用datetimepicker。但是我必须在cs中动态创建它。我通常使用jquery,但是可以接受其他解决方案。

最佳答案

您可以动态创建将jquery脚本附加到控件的脚本:

string csname1 = "BindDatePickerScript";
Type cstype = this.GetType();

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
System.Text.StringBuilder cstext1 = new System.Text.StringBuilder();
cstext1.Append("<script type='text/javascript'>");
cstext1.Append("Your Script");
cstext1.Append("});");
cstext1.Append("</");
cstext1.Append("script>");

cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());
}


该脚本被添加到HTML呈现页面的底部。

09-19 08:29