简体   繁体   中英

Call Java script function in Page load event?

I'm using ASP.NET 4. C#. Is there anyway to call a javascript function or button click event in Page Load?

Thanks

EB

you can use startup script with JavaScript or jquery

string script = "$(document).ready(function() {$('button').trigger('click'); });";
ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);

Yes you can call javascript function through asp.net button like,

By setting OnClientClick property to Javascript function name

or

you can write following in page_load event

Button1.Attributes.Add("onclick","return javascript:f1()");

If you want to call the Button click event in page_load event,

protected void Page_Load(object sender, EventArgs e)
        {
            Button1_Click(sender,e);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Label1.Text = "welcome";
        }

Hope this will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM