admin管理员组

文章数量:1426086

I want to call a javascript function from my codebehind. In my button click event handler I have:

protected void load_data_Click(object sender, EventArgs e)
{
    if (dt.Rows.Count == 1)
        {
            BindDl();                       
        }
        else
        {
            //if dt.rows.count! = 1 I want to call a JavaScript function where be one alert! how to do?
        }
}

I want to call a javascript function from my codebehind. In my button click event handler I have:

protected void load_data_Click(object sender, EventArgs e)
{
    if (dt.Rows.Count == 1)
        {
            BindDl();                       
        }
        else
        {
            //if dt.rows.count! = 1 I want to call a JavaScript function where be one alert! how to do?
        }
}
Share Improve this question edited Feb 24, 2012 at 17:23 Ben 7644 silver badges19 bronze badges asked Feb 24, 2012 at 15:45 AlexAlex 9,74030 gold badges107 silver badges166 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

This page will be helpful for you

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
Type cstype = this.GetType();
String csName = "MyAlertFunction";

// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csName))
{
  String jsFunction = "yourFunctionHere()";
  cs.RegisterStartupScript(cstype, csName, jsFunction, true);
}

user scrip manager

    ScriptManager.RegisterStartupScript(this, typeof(string), "SHOW_ALERT",  "alert('')", true);

where in place of alert you can put your javascript code, next argument true puts in script tags automatically so you dont have to write them.

本文标签: cfrom page *aspxcs call javascript functionStack Overflow