Click here to Skip to main content
15,029,501 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've been searching for an answer to this and it has been posted on forums constantly since about 2005 but I'm still unable to find a solution.

I have a textbox with AutoPostback and a Textchanged event.
Yes, sadly I do need the postback and the event to fire. I've
tried explaining the problems with it but I need to validate the value entered there and then, and to do so I need to hit the DB.
Short of sending all the data I'd need down with the page and writing a complicated Javascript function to do the validation, I can't see any way out of the Postback.

The problem is that if the user edits the data in the Textbox and then clicks Save, the clicking of save causes the focus to leave the textbox thereby calling the Textchanged event. The page postsback and reloads as you'd expect, but the Save button's click event never fires.

The User has to click a second time on the Save button for it to work.

So? How to I fix this?
I can't have the page reloading when the user clicks save without a save actually happening. It fools me and I'm the developer, this is goign to screw users up completely.

-Rd
Posted
Updated 10-Jun-21 0:44am
v3
Comments
Dman01 22-May-17 16:53pm
   
Could you please the code that you used to rectify this problem. This is the same problem I am facing for the last few days.

I agree that the behavior is confusing. I think that the fix would be in taking off the autopost back on the textbox.

I would also suggest that the javascript doesn't need to be complicated at all...especially if you're using a library (like prototype or jQuery) this should be only a couple lines of code.

1) include the script reference for the library in your page
2) write an event handler for the textbox that submits the value to a server-side page
3) display or hide a 'yuep, it validated' DIV on the client.

What version of platforms are you on? I can likely recommend some articles to get started.

Cheers.
   
Comments
Richard A. Dalton 28-Sep-10 10:17am
   
VS2008 & .Net Framework 2.0
SQL Server DB

When I looked at it first I figured I could handle the validation Client-Side. The amound of Data I need to validate against isn't huge, A table with 3 columns and 10's of rows rather than 100's of rows.

I imagined querying the data on the server and inserting it into the page in some way when I sent the page to the client. (Browser Based isn't my comfort zone).

In the end I couldn't figure out what I needed and I went with a Postback, which worked fine until I hit this problem.

You're solution sounds like kind of halfway between the two.

Any tips would be appreciated.

While you're at it, do you know if it is possible to do what I was thinking? Inject data into a page to enable client-side validation?

-Richard
TheyCallMeMrJames 28-Sep-10 10:31am
   
That would definitely work. The easiest approach might be to write the javascript with some of the data baked in to get it working. Then, move to generate the javascript server-side in your aspx page. That way you could write a loop, or a page method (or whatever turns your crank) to generate the data string needed for the client script.

Cheers.
Richard A. Dalton 28-Sep-10 11:04am
   
OK, so what I've done is this. Don't know if it's ideal.
In my page load I fill a hidden Listbox with the valid currencies.
My CustomValidator fires a javascript function that loops through the items in the listbox looking for the currency.

It's working.

Next step, I need to also check the status of the currency. So my Listbox will have items that include the 3 char ccy code plus two chars for status...e.g.

EURUA

To find the currency I search the listbox for a string where the left 3 chars match the ccy entered by the user.
Then I check the remaining two chars to ensure the status is ok.

This crap with the save button was the kick in the ass I needed to do this all on the client.

-Rd
TheyCallMeMrJames 28-Sep-10 11:28am
   
Hope I helped steer you a little. Best of luck with the feature. Cheers.
Richard A. Dalton 28-Sep-10 11:43am
   
Reason for my vote of 5
Automatic vote of 5 for accepting answer.
Richard A. Dalton 28-Sep-10 11:44am
   
You sure did.
Thanks.
i know it,
the button from asp.net once pressed could eventually trigger twice action because at the HTML Interface there's a javascript ONCLICK properties.
Thus, to solve this problem, we should remove that ONCLICK properties. and then re-run again the web app.
Now it's just run once, nor twice. :D
   
Found: when creating control set its id to something. It works, event is fired with one click.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900