问题
I need to call the (window).load(function ())
using C#. Is there anyway that I could accomplish this.
回答1:
Register whatever script you want with RegisterStartupScript:
protected void Page_Load(object sender, EventArgs e)
{
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
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))
{
StringBuilder cstext1 = new StringBuilder();
cstext1.Append(@"$(document).ready(function() {
// Handler for .ready() called.
});");
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString(), true);
}
}
回答2:
No! that is not possible. You can't use client objects in server-side script. For more info read - Using JavaScript Along with ASP.NET
来源:https://stackoverflow.com/questions/7775284/need-to-call-jquery-window-loadfunction-using-c-sharp