Tuesday, February 23, 2010

Window alerts in C#

the javascript way

if(error) //your logic here
  ClientScript.RegisterStartupScript(typeof(Page), "test", "<script>alert('Hello');return false;</script>");

to a button

btn.Attributes.Add("onClick", "javascript:alert('Message Here');");

using messagebox class (using System.Windows.Forms;)

if (MessageBox.Show("Do you want to continue?", "Question", MessageBoxButtons.YesNo) == DialogResult.Yes)
//if user clicks yes, do stuff


System.Windows.Forms.MessageBox.Show("This is a message");

If errors should occur, go to project -> add reference,
then scroll down to System.Windows.Forms and select it.

This will add to web.config:

<add assembly="System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>

Ajax Modal Popup


Using Response on .Net Apps

Response.Write("<script type='text/javascript'>alert('This is my Message')</script>");

Using render objects

(HtmlWriter writer)

writer.Write("<script type='text/javascript'>alert('Hello');return false;</script>");

No comments:

Post a Comment