Don said:
Thanks for the example but I'm really not sure of what you're trying to tell
me. Let's say I have a button in my web application and I want to display a
MessageBox, what would I need to add in my C Sharp code (not the aspx file)
?
private void Button2_Click(object sender, System.EventArgs e)
{
//code to display a Messagebox here that says "Hello worlld"
}
What you need to understand is that there is no way to do this without
client side script. The decision to make is where do you put that
script. You can either put it directly in the aspx file or you can
write some C# code that will inject the script into the response stream
that gets sent to the browser. You must understand that fundamental
concept in order to continue.
There are helper functions in the .NET framework that can aid you in
injecting javascript into the response stream.
If you wanted to put it in your server side click handler it might look
as follows:
private void webButton_Click(object sender, System.EventArgs e)
{
RegisterStartupScript("webButtonClick", "<script
language=\"javascript\">window.alert('you clicked the button');</script>");
}
If the action isn't going to change based on dynamic content that can
only be determined server side after the button is clicked, then it
would be more efficient to either modify the aspx file directly, or add
an attribute to the button in your Page_Load event. Ex:
private void Page_Load(object sender, System.EventArgs e)
{
webButton.Attributes.Add("onclick", "javascript:window.alert('you
clicked the button');");
}