943,828 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1531
  • ASP.NET RSS
Feb 9th, 2008
0

Problem on MessageBox

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ebabes is offline Offline
73 posts
since Sep 2007
Feb 9th, 2008
0

Re: Problem on MessageBox

asp Syntax (Toggle Plain Text)
  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>
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007
Feb 9th, 2008
0

Re: Problem on MessageBox

<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
Reputation Points: 10
Solved Threads: 4
Light Poster
dilipv is offline Offline
30 posts
since Feb 2008
Feb 10th, 2008
0

Re: Problem on MessageBox

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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ebabes is offline Offline
73 posts
since Sep 2007
Feb 11th, 2008
0

Re: Problem on MessageBox

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
Reputation Points: 10
Solved Threads: 4
Light Poster
dilipv is offline Offline
30 posts
since Feb 2008
Feb 12th, 2008
0

Re: Problem on MessageBox

Thanks buddy! But what if I make use of C# as my script? This is what I need. Can you help me please!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
ebabes is offline Offline
73 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: use Timer in global.asax file
Next Thread in ASP.NET Forum Timeline: Problems on hyperlink





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC