ASP.Net & Javascript problem

pdoherty

Newcomer
Joined
Mar 4, 2004
Messages
2
Location
Belfast
Hey,

I am trying to display a javascript 'pop up' alert box when a user clicks on a button. The code I have to do this is below (There is code before this in the event handler but it is not relevant)


Visual Basic:
           Dim sAlert As String = "myalert"
            Dim jscript As String

            jscript = "<script language=javascript>window.alert('Password Change Successful - Redirecting to logon screen');</script>"

            RegisterStartupScript("myalert", jscript)

The problem is that is alert box is not showing!
Stepping through the code everything seems to be ok. No errors or warnings of any sort!

Any ideas?

Cheers
 
i've done something similar with an app that i've created as follows

LinkButton lbtemp = new LinkButton();
lbtemp.attributes.add("onlclick", "<script language=javascript>window.alert('Password Change Successful - Redirecting to logon screen');</script>");
 
unfortunatly this doesnt seem to work either.

A bit more info:

I am trying to run the above piece of code from within an event handler (in the backend .aspx.vb code) for an ASP button, not a HTML button.
 
if you use the code i gave for the alert box ie: <Control>.Attributes.Add("onclick", jscript);

then your event handler has to be a CommandEventHandler

For your button you probably have a OnClick="FunctionName", change this to OnCommand="FunctionName". In your codebehind you've to change the function arguments to object and System.Web.UI.WebControls.CommandEventArgs.
 
Back
Top