By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

Client-side and server side code

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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]

"Stephen" wrote:
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

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.