简体   繁体   中英

fire javascript function from asp.net codebehind

This is my javascript function ,

 function returnToParent() {            
        var oArg = new Object();
        var oWnd = GetRadWindow();
        oArg.ReturnValue = "Submit";
        oWnd.close(oArg);
    }

And this is how I call this function on client side

 <button title="Submit" runat="server" id="close" onclick="returnToParent(); return false;">
                    OK</button>

I want to fire this function in server side button click event .
What I've done is add new button

 <asp:Button runat="server" ID="rtxtSubmitChange" OnClick="rtxtSubmitChange_Click"  Text="Submit" />

and in ButtonClick Event ,

protected void rtxtSubmitChange_Click(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(GetType(),
"MyKey",
"returnToParent();",
false);
    }

But It doesn't work . What I am wrong in my code ?

Try

ScriptManager.RegisterStartupScript(this, this.GetType(), this.ClientID, "returnToParent()", true);

OR

ScriptManager.RegisterStartupScript(Page, Page.GetType(), this.ClientID, "returnToParent()", true);

For more details refer : ScriptManager.RegisterStartupScript Method

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