I have a textbox
in one grid-view column where upon entering a开发者_开发百科 particular value and losing focus of the textbox, should post to the server to get the text validated through a server-side method. If the entry is valid, a result set to fill rest of row cells would be returned, else the bgcolor of the textbox needs to be changed to Red.
I tried posting back through the obvious way, i.e. making the textbox's autopostback
as true
and wiring up a server-side OnTextChanged
event handler to validate the entered value.
It is working with this setup, but is also affecting the remaining page controls behaviour. For example, if I click a button in some other grid after entering some text in the textbox, the OnTextChanged
handler gets called thus preventing the button's click
event, which I also wish to call to execute its functionality.
Kindly suggest what alternatives/corrections I should carry out to enable textbox content server-side validation plus making the other controls/updatepanels work as expected.
Me dumb. I tried everything from creating PageMethods
, UpdatePanels
to jQuery
as hinted in lincolnk's reply. But the thing which finally worked was removing the Autopostback
attribute from the textbox control.
After removing it the OnTextChanged
event executed each time any server postback was initiated after changing the text. Thereby, executing both the OnTextChanged
method and the other control's method. :)
I can think of a couple general approaches.
Create a web service with your validation routine and manually make the call (jQuery or whatever) when the text changes. Manually update the client display when you get a result.
Convert your gridview column to a templated field. Add a
CustomValidator
and wrap the textbox and validator in anUpdatePanel
. Set the textbox to auto-postback and theUpdatePanel
to conditional update so only the one you are using is refreshed.
Option 1 is kind of an end-around the typical asp.net process, and you would still want to validate everything on the server-side when the page is posted back.
Option 2 might have performance issues, since you're hitting the page again every time you do a validation.
精彩评论