 |
| ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

April 4th, 2004, 08:59 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i meeted the same question a few days before, i know i can't use messagebox directly, so i used a row of code like this in my .aspx. vb file:
button1.Attributes.Add("onclick", "window.alert('The username can't be null!');")
but the question is i don't know how to control it under a condition of "If userName.Text = Nothing", please help me, thanks
Do better than yesterday!
|
|

April 4th, 2004, 09:17 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
or how to realize the alert message with javascript in the .aspx. vb file?
|
|

April 4th, 2004, 10:37 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
here is my code in my .aspx. vb file, i want to alert user if he don't input his name in the login page:
Private Sub btnEnter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEnter.Click
If txtName.Text = Nothing Then
btnEnter.Attributes.Add("onclick", "window.alert('The username can't be NULL!');")
Exit Sub
End If
End Sub
but it can't work as i expected, but i don't know how to modify it, how to touch off the attribute under the assigned condition?
|
|

April 4th, 2004, 11:16 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
add a function in ut <script> & call it validating()
then set ur last code as
button1.Attributes.Add("onclick", "validating();")
then u can control all u want there & aleret in the case want!
HTH.
Always:),
Hovik Melkomian.
|
|

April 5th, 2004, 12:51 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
after i add the attributes, only when i click my left button at the second time, it can work to alert, how can make it work at the first click?
|
|

April 5th, 2004, 03:10 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Ensure u have added it in ur PostBack, check that & set it in first line of page_load.
Always:),
Hovik Melkomian.
|
|

April 5th, 2004, 06:30 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Quote:
quote:Originally posted by brzhang
Private Sub btnEnter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEnter.Click
If txtName.Text = Nothing Then
btnEnter.Attributes.Add("onclick", "window.alert('The username can't be NULL!');")
Exit Sub
End If
End Sub
|
You are missing a fundamental concept. This is code-behind code. "btnEnter_Click()" will only run when the page is posted back. You must add the attribute to the button unconditionally (i.e. in page_load or similar). Then you need to do your text test in javascript, not in the code behind.
Try this:
btnEnter.Attributes.Add("onclick", String.Format("if(document.getElementById('{0}').v alue==''){window.alert('The username can't be NULL!');return false;}else{return true;}", txtName.ClientId))
This will test the value of the textbox for '' and put up the alert, then return false if it's empty. If not, it will return true. The end result is that if the test passes, the button should fire the postback. If the textbox is empty, the button should NOT fire the postback. (Please note, I have not tested this exact code.)
|
|

April 5th, 2004, 08:28 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i add your code in my sub Page_Load, as follow:
btnEnter.Attributes.Add("onclick", String.Format("if(document.getElementById('{0}').v alue==''){window.alert('The username can't be NULL!');return false;}else{return true;}", txtName.Text))
when i run, i get the error: System.FormatException: format of input string is not correct.
i think i can't accurately understand your "getElementById" and "txtName.ClientId".
|
|

April 5th, 2004, 11:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
if u ask me I'll call only a JavaScript-function by clicking button from Behinde page & then use my all conditions & ... from there, it'll help u to see where is the problem from.
Always:),
Hovik Melkomian.
|
|

April 6th, 2004, 12:33 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i know ur JavaScript-function , but i don't know how to use it.i develop my page with .net,the code is in a code-behind ". vb" file. <script></script> is not allowed, i can alert my user with a label control, but i prefer to the "window.alert".
Do better than yesterday!
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Msgbox Help |
darrenb |
Access VBA |
2 |
June 8th, 2007 12:53 AM |
| MsgBox |
prabodh_mishra |
Pro VB 6 |
1 |
December 29th, 2006 11:51 AM |
| msgbox |
Ramakrishna.G |
General .NET |
3 |
September 14th, 2004 02:17 AM |
| help with Msgbox |
helmekki |
Excel VBA |
2 |
June 25th, 2004 08:24 AM |
| msgbox |
bph |
Access VBA |
2 |
February 6th, 2004 03:00 PM |
|
 |