Problem on MessageBox

Please support our ASP.NET advertiser: $6.99 Domain Names at 1&1. Includes Free Privacy. Save Now!
Reply

Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Problem on MessageBox

 
0
  #1
Feb 9th, 2008
I wish to display a MessageBox when a user had entered an invalid input in a textbox. How can I do this using C# as my script?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,650
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 249
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Problem on MessageBox

 
0
  #2
Feb 9th, 2008
  1. < %@ Page Language="C#" %>
  2. < script runat="server">
  3. void AlertBtn_Click(object sender, EventArgs e)
  4. {
  5. string showmessage = "Test Message Box";
  6. string alertScript = "< script language=JavaScript> ";
  7. alertScript += "alert('" +showmessage +"');";
  8. alertScript += "< /script" +"> ";
  9.  
  10. if (!IsClientScriptBlockRegistered("alert"))
  11. this.RegisterClientScriptBlock("alert", alertScript);
  12. }
  13. < /script>
  14. < html>
  15. < head>
  16. < /head>
  17. < body>
  18. < form runat="server">
  19. < asp:Button id="btn" onclick="AlertBtn_Click"
  20. runat="server" Text="Button"> < /asp:Button>
  21. < /form>
  22. < /body>
  23. < /html>
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 30
Reputation: dilipv is an unknown quantity at this point 
Solved Threads: 4
dilipv dilipv is offline Offline
Light Poster

Re: Problem on MessageBox

 
0
  #3
Feb 9th, 2008
<script language="javascript" type="text/javascript">
function confirm()
{
if (confirm ==true)

else

return false;

}
</script>
then write in .aspx.cs
ButtonSave.Attributes.Add("onclick", "return confirm('Are you sure you proceed?');");

hope this code will help you out.

Thank tou
Jitesh
.Net Consulting
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Re: Problem on MessageBox

 
0
  #4
Feb 10th, 2008
Thanks. But just a sort of clarification, let's say what if a user had entered an invalid age in a textbox. And then a messagebox will pop up with a message "Sorry, your age is not qualified!". How can I do this?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 30
Reputation: dilipv is an unknown quantity at this point 
Solved Threads: 4
dilipv dilipv is offline Offline
Light Poster

Re: Problem on MessageBox

 
0
  #5
Feb 11th, 2008
hi ebabes,


if you use the dropdownlist and add the number in to it, then there is no question of user making the mistake and so no need to prompt too..

Visual Basic code

Private flag As Boolean

Private Sub MyTextChangedHandler(sender As System.Object, e As System.EventArgs)
' Check the flag to prevent code re-entry.
If flag = False Then
' Set the flag to True to prevent re-entry of the code below.
flag = True
' Determine if the text of the control is a number.
If IsNumeric(textBox1.Text) = False Then
' Display a message box and clear the contents if not a number.
MessageBox.Show("The text is not a valid number. Please re-enter")
' Clear the contents of the text box to allow re-entry.
textBox1.Clear()
End If
' Reset the flag so other TextChanged events are processed correctly.
flag = False
End If
End Sub

Hope this will help you out.

Thank you
Jitesh
.Net Consulting
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 73
Reputation: ebabes is an unknown quantity at this point 
Solved Threads: 0
ebabes's Avatar
ebabes ebabes is offline Offline
Junior Poster in Training

Re: Problem on MessageBox

 
0
  #6
Feb 11th, 2008
Thanks buddy! But what if I make use of C# as my script? This is what I need. Can you help me please!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1350 | Replies: 5
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC