|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Validator ControlA little about my situation(fairly simple)...I have an ASP.NET page containing a number of TextBox controls with a button named "Update" which saves all entered values back to the database. When the page is loaded the controls contain the original values retrieved from the database. I have a few ValidatorControls on this page and each of these are attached to one of the Textboxes. For the most part, the ValidatorControls are checking to ensure a value is present. The validation works great...but, when I click on the "Update" button (which attempts to save all newly entered data back to the database), I'm unable to retrieve any new values entered in the Textboxes. The TextBox.Text properties of all textboxes on the page are equal to the values that were initially assigned to them when the .aspx page was loaded. I must confess (and as you've already probably discerned by now), I'm a Newbie...my meager understanding of the problem at this point is it's b/c the ValidatorControls are disallowing the page to PostBack to the server? I understand the ideal way to handle this would be to use JavaScript. I guess my question comes down to this...is there something simple I'm missing and that I could change to make the TextBox.Text property reflect the newly entered data. Or should I just scrap these ValidatorControls and write JavaScript to do this. Thanks for your time and any advice on this would be greatly appreciated. Regards, Jim Hi Jim,
The validators can prevent the page from being submitted but they cannot edit the values of the textbox. If you are getting the page to submit, next you should see your button's Click event method fire. That's where you put your data storage code, right? First, make sure it tests Page.IsValid is true before saving. That is required when using validation controls. Now why would the data be restored to its defaults? My guess is that somewhere on the page, you have code that sets the controls to their defaults and that code is actually being fired on post back. You have forgotten to block it with a test of Page.IsPostBack = false. --- Peter Blum www.PeterBlum.com Email: PLB***@PeterBlum.com Creator of "Professional Validation And More" at http://www.peterblum.com/vam/home.aspx Show quoteHide quote "Jim" <JS***@dot.state.az.us> wrote in message news:1115319222.533399.47790@z14g2000cwz.googlegroups.com... > Greetings, > > A little about my situation(fairly simple)...I have an ASP.NET page > containing a number of TextBox controls with a button named "Update" > which saves all entered values back to the database. When the page is > loaded the controls contain the original values retrieved from the > database. > > I have a few ValidatorControls on this page and each of these are > attached to one of the Textboxes. For the most part, the > ValidatorControls are checking to ensure a value is present. The > validation works great...but, when I click on the "Update" button > (which attempts to save all newly entered data back to the database), > I'm unable to retrieve any new values entered in the Textboxes. The > TextBox.Text properties of all textboxes on the page are equal to the > values that were initially assigned to them when the .aspx page was > loaded. > > I must confess (and as you've already probably discerned by now), I'm a > Newbie...my meager understanding of the problem at this point is it's > b/c the ValidatorControls are disallowing the page to PostBack to the > server? I understand the ideal way to handle this would be to use > JavaScript. > > I guess my question comes down to this...is there something simple I'm > missing and that I could change to make the TextBox.Text property > reflect the newly entered data. Or should I just scrap these > ValidatorControls and write JavaScript to do this. > > Thanks for your time and any advice on this would be greatly > appreciated. > > Regards, > Jim > Peter,
Thanks for your time and yep, you're exactly right. I didn't have the "IsPostBack == false" test. I actually figured this out a couple of hours after making this post on groups.google.com. I removed it but I guess its removal wasn't propogated to developersdex.com. Sorry 'bout that. Nonetheless, Thank You again for taking time to reply!! Regards, Jim *** Sent via Developersdex http://www.developersdex.com ***
DropDownList - Programmatically setting the background colour of i
Drop down list viewstate; please HELP! Change print orientation by website Image auto sizing in asp.net VS.NET 2003 using ASP.NET & VB.NET -- IDE design time problems? custom webcontrol : render and then get "html" result in server side Adding control to datagrid Empty column Column span datagrid header How to make datagrid headders non Scrollable in a multi page contr |
|||||||||||||||||||||||