Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Message Box Confusion

Status
Not open for further replies.

mtl77

Programmer
May 27, 2003
31
CA
Is it possible to display a yes/no message box when a user clicks on a delete button column in a datagrid? Also can I access the value from that message box in the code behind file? I am having trouble understanding how to access javascript return values from the code behind pages, so if some one could explain that to me, i would really appreciate it.

Thanks in advance for your help.

Mtl77.
 
You can use the MessageBox Server control. One of it's overloaded Show() methods allows you to specify buttons. The method returns a DialogResult.

Code:
DialogResult result = MessageBox.Show("Message",
  "Dialog Caption",MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
{
  //User clicked OK
}

Thomas D. Greer
 
Thanks, but where do i find the Message Server Control, i have never heard of that.
 
System.Windows.Forms.MessageBox... whoops. This is the ASP.NET forum, not the C# forum. Umm, sorry! Ignore my previous post, what you want is the JavaScript "Confirm()" method.

It returns a boolean, true if the user clicks "OK" and false if they click "Cancel".

What you need to do is write a JavaScript such as:

Code:
<script>
function confirm_me()
{
  input_box=confirm(&quot;Click OK or Cancel to Continue&quot;);
  if (input_box==true)
  { return true; 
  }
  else
  { return false;
  }

}
</script>

Tie that code to your onClick attribute. You can replace the &quot;return true&quot; to a Form.Submit() to send the form back to the server for processing.

Thomas D. Greer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top