1

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 ?

11
  • I'm surprised you managed to compile this. OnClick is to be handled on the server side (C#), and OnClientClick on the client (Javascript). So, besides fixing your markup, you should call the Javascript function from the server side just if there's something you need to do before doing so. Otherwise, just use the OnClientClick. Commented Dec 18, 2013 at 9:12
  • Please check if javascript file containing function is available. If so check if function is available or not. Sometimes js files are cached & new functions definitions thus are not available Commented Dec 18, 2013 at 9:13
  • @MelanciaUK , actually I don't need to use client side . I've to make some CUD function in server side and then to fire this javascript function . Thanks ! Any advice ? Commented Dec 18, 2013 at 9:16
  • 1
    Then you should have OnClick="rtxtSubmitChange_Click". Commented Dec 18, 2013 at 9:17
  • 1
    Page.ClientScript is deprecated. Use ClientScriptManager instead. But if you're playing with UpdatePanels, use ScriptManager instead. Also, when you stick a breakpoint on the click handler, does it get hit? Commented Dec 18, 2013 at 9:30

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.