Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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
 
Old March 10th, 2010, 11:08 AM
Banned
 
Join Date: Jan 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
Default Chapter 9 ErrorMessage / Button Click

After completing the first "Try it out" on page 296, I wanted to try something different. I added some code in the code behind file Controls/ContactForm.ascx.vb for the button_click sub for the Send button. The code is supposed to display the ErrorMessage from the RequiredFieldValidator1 control in a label that I added, if the text box for the name is empty. To debug the code, I put a breakpoint on the button_click sub for the Send button, but it only steps through the code when I put and name in the box and click Send. It will not step throught the sub if the text box is empty and I click send. I'm I forgetting something from a previous lesson?
Here's my code:

Code:
 
Partial Class Controls_ContactForm
    Inherits System.Web.UI.UserControl

  Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click

    If txtName.Text = String.Empty Then
      lblForMessage.Text = RequiredFieldValidator1.ErrorMessage.ToString
    End If


  End Sub
End Class
 
Old March 10th, 2010, 11:16 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Isn't RequiredFieldValidator1 preventing you from submitting to the server in the first place?

What exactly are you trying to accomplish? Can you post the relevant pieces of code from the markup and Code Behind?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old March 10th, 2010, 12:01 PM
Banned
 
Join Date: Jan 2010
Posts: 22
Thanks: 10
Thanked 0 Times in 0 Posts
Default

Tell me if this is true: The button_click sub is not executed if the validation fails (Last 2 sentences under "How it works", page 296.) That is why it doesn't step into the routine. In other words, if validation fails the button_click sub is not executed even though you click the button. ASP doesn't waste time executing the sub and submitting to the server if validation fails at the client. Is this correct?
What I was trying to do is write some code to display both the error Text "*" in one cell and the ErrorMessage in a seperate label that I put in another cell in the table. Just trying experiment a little.

Thanks,

Chuck
 
Old March 10th, 2010, 12:24 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
ASP doesn't waste time executing the sub and submitting to the server if validation fails at the client. Is this correct?
Yes, but in reversed order.

ASP.NET validation is split in two parts: client side and server side. When client side validation fails the page does not submit to the server and ASP.NET never comes into play. So, it doesn't execute the Sub as the request never makes it to the server.

Once you turn client side validation off, the page does submit to the server where your code will run. Just to clarify once more: client side validation should only be used as a courtesy to the user. You shouldn't rely on it for true validation purposes; you must use server side validation for this.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
ChuckASP (March 10th, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to button click Y/N in an email and kenn_rosie VB.NET 2002/2003 Basics 0 March 2nd, 2006 07:36 PM
Button Click ~Bean~ ASP.NET 1.0 and 1.1 Basics 2 September 27th, 2005 09:32 AM
Login Click Button mrideout BOOK: Beginning ASP.NET 1.0 6 August 12th, 2004 10:11 AM
Print on Button Click mahulda ASP.NET 1.0 and 1.1 Basics 2 August 5th, 2004 02:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.