is there an error here ?

G

Guest

Please check the string in "stralertscript ".

if ( ds.Tables["studentTestpaper"].Rows.Count == 0 )
{
stralertscript = "<script language='javascript'> "+
" function alert() "+
" { "+
" alert ('Testpaper not found'); "+
" return true; "+
" } </script> ";

Page.RegisterStartupScript ("stralertscript", stralertscript);
}

What I wanted to do was to pop up an alert message. The IF function works
fine, but the alert doesn't appear. Should I use RegisterStartupScript or
RegisterClientScriptBlock ?

TIA
Andrew.
 
K

Karl Seguin

My guess is that your problem is the name of your function. You have a
function named "alert" which is a javascript built-in function. It's no
different than if you tried to name your function "if" or "true" Simply
renaming the function to something else. Use RegisterClientScriptBlock.

Karl
 
C

Chris Botha

In addition to incorrectly using "alert" as your function name, you say
"What I wanted to do was to pop up an alert message".
So I understand that when the page loads on the client side you want the
message to pop up? Then something must call the function as well. If so,
then changing your "stralertscript =" to the following will give the pop up,
and use RegisterClientScriptBlock

stralertscript = "<script language='javascript'> "+
" alert ('Testpaper not found'); "+
"</script> ";
 
G

Guest

Hi,

Thanks for your reply. I tried changing that alert word to stralert, but it
still doesn't work, i simply do not see any alert msges pop-ing up on my
screen, lolz....

I found out that I could use this line to solve my problem:
Response.Write("<script language='javascript'> alert('Testpaper not found');
</script>");

This works. I do see an alert message pop-up.
Still dun know why my previous code does not work. The debugger just goes
pass those lines.

cheers,
Andrew.

Karl Seguin said:
My guess is that your problem is the name of your function. You have a
function named "alert" which is a javascript built-in function. It's no
different than if you tried to name your function "if" or "true" Simply
renaming the function to something else. Use RegisterClientScriptBlock.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!



Andrew said:
Please check the string in "stralertscript ".

if ( ds.Tables["studentTestpaper"].Rows.Count == 0 )
{
stralertscript = "<script language='javascript'> "+
" function alert() "+
" { "+
" alert ('Testpaper not found'); "+
" return true; "+
" } </script> ";

Page.RegisterStartupScript ("stralertscript", stralertscript);
}

What I wanted to do was to pop up an alert message. The IF function works
fine, but the alert doesn't appear. Should I use RegisterStartupScript or
RegisterClientScriptBlock ?

TIA
Andrew.
 
G

Guest

Thanks for your replies.

Chris Botha said:
In addition to incorrectly using "alert" as your function name, you say
"What I wanted to do was to pop up an alert message".
So I understand that when the page loads on the client side you want the
message to pop up? Then something must call the function as well. If so,
then changing your "stralertscript =" to the following will give the pop up,
and use RegisterClientScriptBlock

stralertscript = "<script language='javascript'> "+
" alert ('Testpaper not found'); "+
"</script> ";


Andrew said:
Please check the string in "stralertscript ".

if ( ds.Tables["studentTestpaper"].Rows.Count == 0 )
{
stralertscript = "<script language='javascript'> "+
" function alert() "+
" { "+
" alert ('Testpaper not found'); "+
" return true; "+
" } </script> ";

Page.RegisterStartupScript ("stralertscript", stralertscript);
}

What I wanted to do was to pop up an alert message. The IF function works
fine, but the alert doesn't appear. Should I use RegisterStartupScript or
RegisterClientScriptBlock ?

TIA
Andrew.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top