0

I'm trying to call a javascript alert from a master page, where i got an update panel. Within that a button and a text box.

I need to call the alert on clicking the button in my master page. So far it seems not working. Please help.

 Page.ClientScript.RegisterStartupScript
                        (this.GetType(), "alert", "invokeMeMaster();", true);

This is what i wrote in my button click. invokerMEMaster include just an alert message.I need to reload the page on the ok button click of the alert. How can i do that as well?

1
  • 3
    Can you post the code that isn't working? Commented Jul 20, 2011 at 10:10

4 Answers 4

1

Update Panel clears javascript code when Postback so try to put this code on the header.

<script type="text/javascript">

$(document).ready(
function(){

   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); 
   function EndRequestHandler(sender, args) {//put your code here}

});

</script>
Sign up to request clarification or add additional context in comments.

1 Comment

i need to add alert messages from code behind...How am i supposed to call my script if im using this in the source page?
0

You need a ScriptManagerProxy, with the ScriptManager residing in your content page

Comments

0

If I may guess your problem (psychic debugging): When the update panel updates the javascript is not rendered of fired on your page.

Try to register your javascript like in the update panel:

ScriptManager.RegisterClientScriptBlock(Page,typeof(string),"JavaScriptCall",script.ToString(), false);

Comments

0

If I understand your question correctly you have a JS function in a content page that needs to be called from the master page?

What I would do is add a hidden input control and an alert function to your master page:

    <input runat="server" id="hdnAlert" name="Alert" type="hidden" />

    <script type="text/javascript"  language="javascript">  
        function AlertMe(){ alert(document.getElementByID("hdnAlert").value); }
    </script>

You could then change the value of the input control from a content page:

    HtmlInputHidden hdnTemp = new HtmlInputHidden();
    hdnTemp = (HtmlInputHidden)Master.FindControl("hdnAlert");
    hdnTemp.Value = "Message To Alert";

Then just have the button in your master page call the "AlertMe" function located in the master page.

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.