Ebikeneser
Ebikeneser

Reputation: 2364

Javascript pop up not loading

I have the following code behind -

int p = 0;

        try
        {

            p = System.Convert.ToInt16(txt7.Text);
        }
        catch
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "showMyMessage", "ShowMessage('Value must be numerical');", true);
        }

And the function -

 <script>

  function ShowMessage(message) { alert(message); }

</script>

On debugging it goes into the catch however the pop up is not firing in the front end, what is it I am missing?

Upvotes: 0

Views: 106

Answers (3)

coder
coder

Reputation: 2000

Add type of script and place script at the top..

 <script type="text/javascript">

 funcion ShowMessage(message)
 {
  alert(message);
 }

</script>

Upvotes: 0

Axel
Axel

Reputation: 361

If you are using UpdatePanels, then you should instead use ScriptManager.RegisterStartupScript

Upvotes: 1

K D
K D

Reputation: 5989

Place your script at the top of the page (inside your body tag or head tag) as that could be the reason for it.. The startup scrip call should be below your mentioned script. and for best practice please write it like this

<script type="text/javascript">

  function ShowMessage(message)
   {
        alert(message); 
   }    
</script>

Upvotes: 1

Related Questions