ASP.Net Textbox loses value on button click

Associate
Joined
25 Feb 2007
Posts
905
Location
Midlands
Hi,

I have a textbox and a submit button in a hidden div (this div is shown when a different button is clicked).

With the above set up, when the submit button is pressed, the value of the textbox is set to "" when debugging the submit button onclick handler.

If the div isn't hidden, the submit button works as expected and the textbox retains it's value.

Any ideas how I can keep the textbox value with the hidden div? This is in C#.

Thanks,
Matt
 
Associate
OP
Joined
25 Feb 2007
Posts
905
Location
Midlands
OK, since posting this I've made some progress.

The div is a jQuery UI Dialog widget, with it's autoOpen option set to false when the page loads. The button then calls the dialog's Open() function, which then shows the div.

However, I've since found that the dialog appends itself to the body rather than the form (from this link) so I've added the following line after the dialog is initiated:

Code:
$("#dialog").parent().appendTo(jQuery("form:first"));

This resolves the problem of the textbox losing it's value.
 
Associate
OP
Joined
25 Feb 2007
Posts
905
Location
Midlands
OK so as a result of doing the above, if I set the 'modal' property to true, it disables all elements on the screen, so the dialog becomes disabled too!

Can anyone shed some light on how I can use the modal property without it disabling the dialog?
 
Associate
OP
Joined
25 Feb 2007
Posts
905
Location
Midlands
I'm not sure that the hidden field would retain it's value either, why would that behave any differently than the textbox?

I'll give it a try, but if you could expand on your answer that would be great :D

Every solution I've seen to my initial problem was to move the dialog position in the DOM...
 
Associate
OP
Joined
25 Feb 2007
Posts
905
Location
Midlands
Ah I see what you mean, I was thinking that the HiddenField would be inside the Dialog too.

How would I set the value of the HiddenField to be the same as the Textbox? If I use the TextChanged handler for the TextBox, it doesn't fire, which I assume is because it's been moved by jQueryUI?
 
Last edited:
Back
Top Bottom