Client-side and server side code

G

Guest

Hey Everyone,
I have a problem with a web application due to the use of both client-side
and server side script on the on-click event of a button. The client side
script runs first as expected however my problem is that this code runs and
brings up a Microsoft Internet Explorer Window telling the user they are
going to be charged for the search they are about to do. The user then has to
click ok or cancel. My problem with this is that I need the server-side
validation code to run before it. The validation has to be done server side
but I need it to kick in before the message to the user pops-up. I don't want
the message to come up at all if the user details aren't valid.
I don't mind changing my client side code if I have to in order to achieve
this.

Does any one know how I can achieve this? Does anyone know how to get
Internet Explorer messagesboxes popping using c# code in the code behind page
on the buttons onclick event.
Cheers for any help anyone can give me
 
G

Guest

hi stephen,

As far as i have worked, there is not way to restrict the order in which the
client and server event is fired, the client events are fired first, b4 the
server.

But a workround for your case might be to render the java script from the
code behind class.

Try this code in the button click event.

Response.Write("<Script>alert('hi')</script>");
this shows an alert box on click of the button, you can play around with
your javascript to get the exact functionality what you wanted......

To add a confirm box to ur code, try this.

Button1.Attributes.Add("OnClick", "return confirm('Are you Sure you want to
delete this?');");

you can get the message box dialog result like this.
set the CommandArgument Property to some text and check the text in the
button click event.
If the text matches the user has clicked "OK", else cancel.

Ex:
Button1.CommandArgument = "YES";

private void Button1_Click(object sender, System.EventArgs e)
{
//returns "YES" when OK is clicked in the confirm window.
string str1 = ((Button)sender).CommandArgument;

if (str1 == "YES")
{
//add code to do task
}
else
{
//do someother task
}
}

Hope this helps,
Kannan.V [MCAD.net]
 

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