Need to call jQuery (window).load(function ()) using c#

只谈情不闲聊 提交于 2019-12-13 03:31:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!