Wrox Programmer Forums
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 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 June 15th, 2007, 08:39 AM
Registered User
 
Join Date: Jun 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default form postback and validation

Hi,
I am new to .Net and come from Java.

I have a form in a page. I tell the form to go to a second page in the Button object with postbackurl. Before, I make some validation using a CustomValidator. The method in the validator just sets the args.IsValid to false. In case of a bad validation, I am redirected to the second page, instead of staying at the same page, though the validation method is called.

My code:
Validation:
public void myValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
    {
        if (...)
        {
            args.IsValid = false;
        }
    }

Button definition:
<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="~/secondpage.aspx" />

Any hint on what goes wrong?

Thank you
Samuel



 
Old June 15th, 2007, 09:24 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What does your button code look like?

You need to check Page.IsValid before redirecting.

http://msdn2.microsoft.com/en-us/lib...e.isvalid.aspx

-Peter
 
Old June 15th, 2007, 09:41 AM
Registered User
 
Join Date: Jun 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Peter,
Thank you very much for you answer. My button code creates an object and redirects to another page.

Now, I check Page.IsValid as you've said and I it is working.

Thanx again
Samuel

 
Old June 15th, 2007, 09:46 AM
Registered User
 
Join Date: Jun 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear Peter,

If I do like you say, and then redirect to the form page instead of the success page, the error text of the validator is not shown.

What am I doing wrong?

Samuel

 
Old June 19th, 2007, 08:31 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

ASP.NET web forms mostly eliminate the need for any kind of error page. Instead you should present the error in the page with the form entry fields. Usually the validator would be located right next to the entry field it is validating. Thus, when you submit with invalid data the user sees this next to the invalid field. Only when you get a valid entry for everything would you do some action and redirect the user to a success notice page.

When you run validation logic and set the IsValid property of a validator to true, the page framework will automatically configure the validator so it will show up when the page is rendered and emitted to the user.

-Peter
 
Old July 17th, 2007, 12:23 AM
Authorized User
 
Join Date: Jul 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Checkout both these links

http://www.dotnetuncle.com/Aspnet/59_page_redirect.aspx

http://www.dotnetuncle.com/Aspnet/81...0controls.aspx

HTH

Cheers

VK


http://www.dotnetuncle.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Validation\Postback bug TheNinthPlayer ASP.NET 3.5 Basics 1 June 6th, 2008 01:00 AM
Validation controls and postback sdi126 ASP.NET 2.0 Basics 5 November 11th, 2007 12:08 PM
Validation control and postback Chaotix ASP.NET 1.0 and 1.1 Basics 0 July 18th, 2006 12:31 PM





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