javascript validation

M

Mike P

I have a method that I use for Javascript validation (see below). What
I want to do is change the alert title, buttons, icon etc. Does anybody
know the correct syntax to do this?

private void Gen_Alert(string Key, string msg)
{
string str = "";
str += "<script language='javascript'>";
str += "alert('"+msg+"')";
str += "</script>";
RegisterStartupScript(Key, str);
}


Cheers,

Mike
 
K

Kevin Spencer

You can't. There are several pre-defined functions in JavaScript that do
similar things. The alert() function simply pops up a MessageBox with an OK
button on it. The confirm() function pops up a MessageBox with an OK and
Cancel button, and returns true if OK is clicked, and false if Cancel is
clicked. The propmt() function pops up a MessageBox with a text box and an
OK button, and returns the string entered into the text box.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.
 
M

Mike P

Kevin,

Thanks for the info about confirm() and prompt(), they may come in
useful!


Cheers,

Mike
 
K

Kevin Spencer

You're quite welcome, Mike. I probably should have mentioned another, more
difficult alternative, which is to design a popup that does whatever you
need. It is more difficult because, for example, many browsers don't allow
popups. This can be overcome, however, by the use of an
absolutely-positioned div with a zIndex higher than the rest of the page.
Making it look like a dialog box is somewhat problematic, and unlike a
regular popup, its position is nailed to the position of the window below
it. It also requires a good bit of DHTML (JavaScript/HTML/CSS) programming
to use it, but if you design it well, it can be re-used in the same (and
other) web applications. The greatest difficulty with this sort of solution
is making it look and behave more or less the same in all browsers. But it
can certainly be done.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.
 

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