Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET 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 4th, 2004, 04:33 PM
Authorized User
 
Join Date: Jan 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rathbird
Default Posting form After Custom Client-side validation

I have to perform line item validations based on whether an item is checked or not; essentially formatting and values in four fields depending on whether the first field is checked. I do this with a javascript validation.

I can't use the custom validator to call this function because it is a form-level check, not a control-level check. To get this to work, I placed an onsubmit event handler in the form element. To have this event invoked, I needed to use an html submit button instead of an <asp:button>. So my validation is working fine, but once it returns true, I have no event to fire that posts the form back to the server, i.e., without the asp:button, I don't have the button clicked event to call the code to process the form. How do I do this?

Any help would be greatly appreciated!

 
Old March 4th, 2004, 05:29 PM
Authorized User
 
Join Date: Jan 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rathbird
Default

I actually solved this problem myself! I have two buttons, one the html submit button which fires the client-side validation, and the other which submits to the server. I have a Total field which is calculated at the end of the validation, and I have a requiredfieldvalidator on this control, so they can't click the asp:button without running the client-side validation!

Without the total field, I could always use a hidden field to do the same thing, but then the user would be hitting two buttons, and that would be odd. So, although my current problem is solved, I'm still curious how to handle it with the single button.

If anyone wants to see this form in action, it's at http://www.celibre.com/admin/consult.aspx. I've set up a guest password for wrox users, username is guest, pwd is wroxRu!es

 
Old March 4th, 2004, 05:44 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can use an asp:Button instead of an HTML button. You can add code to the onclick handler for the button that calls a custom function you have in your page. If the function returns false, the form is not posted back to the server.

Here's the general idea:

ASPX page
function MyTest()
{
  if (bla)
  {
    return true;
  }
  else
  {
    return false
  }
}


Code Bind for your Page
MyButton1.Attributes.Add("onclick", "return MyTest();");

When you now click the ASP button, first (before the page is submitted), MyTest is called. If Bla, the page is submitted as normal. If bla is false, the user stays where he was.

Does this help?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 4th, 2004, 06:03 PM
Authorized User
 
Join Date: Jan 2004
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rathbird
Default

Imar, wonderful solution! thanks for the help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Client Side Validation anujrathi ASP.NET 1.0 and 1.1 Professional 1 June 17th, 2006 10:23 PM
Custom Validation Control Client side event rodmcleay ASP.NET 1.0 and 1.1 Basics 3 December 17th, 2004 08:47 AM





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