Postback nightmares

D

Doogie

Basically, I have two custom dates the user can enter via a popup
calendar. These dates are stored into text boxes. Then the user can
click a button (Run Report) and those values (as well as others) are
used to build an SRS url string. This used to work before I modified
the page to make the calendar a popup.

Now, the text boxes lose their value when the user clicks the run
report button. I have verified this is happening because it’s doing a
postback, but the values are gone before page_load is called. I have
EnableViewState set to true for both text boxes and it’s not retaining
the values. I have tried variations of ways to fix this (set the
values in a view state object, enable view state on the page as a
whole, etc) and nothing is working.

Am I missing something?
 
P

Peter Bromberg [C# MVP]

It sound like you are capturing the entered values from the popup
client-side, and therefore there is no server-side TextChanged event or
ViewState populated.
Of course, when the postback is created, you get two empty textboxes because
valuess populated in the browser don't get transmitted. Among other tricks,
you could try storing them in a cookie first - that can be done client-side
via javascript. Then read back the cookie on a postback and you can get your
values.
Peter

Basically, I have two custom dates the user can enter via a popup
calendar. These dates are stored into text boxes. Then the user can
click a button (Run Report) and those values (as well as others) are
used to build an SRS url string. This used to work before I modified
the page to make the calendar a popup.

Now, the text boxes lose their value when the user clicks the run
report button. I have verified this is happening because it’s doing a
postback, but the values are gone before page_load is called. I have
EnableViewState set to true for both text boxes and it’s not retaining
the values. I have tried variations of ways to fix this (set the
values in a view state object, enable view state on the page as a
whole, etc) and nothing is working.

Am I missing something?
 
D

Doogie

It sound like you are capturing the entered values from the popup
client-side, and therefore there is no server-side TextChanged event or
ViewState populated.
Of course, when the postback is created, you get two empty textboxes because
valuess populated in the browser don't get transmitted. Among other tricks,
you could try storing them in a cookie first - that can be done client-side
via javascript. Then read back the cookie on a postback and you can get your
values.
Peter


Basically, I have two custom dates the user can enter via a popup
calendar.  These dates are stored into text boxes.  Then the user can
click a button (Run Report) and those values (as well as others) are
used to build an SRS url string.  This used to work before I modified
the page to make the calendar a popup.

Now, the text boxes lose their value when the user clicks the run
report button.  I have verified this is happening because it’s doing a
postback, but the values are gone before page_load is called.  I have
EnableViewState set to true for both text boxes and it’s not retaining
the values.  I have tried variations of ways to fix this (set the
values in a view state object, enable view state on the page as a
whole, etc) and nothing is working.

Am I missing something?

Turns out that the fact the text boxes are disabled is what is causing
the issue. Setting them to be enabled fixed the issue. Weird, not
sure why I wouldn't be able to do that. I have them disabled cause I
wanted them to only be filled by the calendar popup and not manually
entered.
 
T

Teemu Keiski

Hi,

You could set submitdisabledcontrols="true" on the <form> element of the
page which makes asp.net to post also disabled textboxes values. I believe
disabled HTML form elements don't submit by default.

Other option is to set TextBox as readonly but that has to be done via
Attributes.Add
(http://aspadvice.com/blogs/joteke/archive/2006/04/12/16409.aspx) as setting
ReadOnly property prevents postback data from being loaded, meaning in
practise that TextBox doesn't keep its state (it's read-only from
server-side perspective)


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


It sound like you are capturing the entered values from the popup
client-side, and therefore there is no server-side TextChanged event or
ViewState populated.
Of course, when the postback is created, you get two empty textboxes
because
valuess populated in the browser don't get transmitted. Among other
tricks,
you could try storing them in a cookie first - that can be done
client-side
via javascript. Then read back the cookie on a postback and you can get
your
values.
Peter


Basically, I have two custom dates the user can enter via a popup
calendar. These dates are stored into text boxes. Then the user can
click a button (Run Report) and those values (as well as others) are
used to build an SRS url string. This used to work before I modified
the page to make the calendar a popup.

Now, the text boxes lose their value when the user clicks the run
report button. I have verified this is happening because it’s doing a
postback, but the values are gone before page_load is called. I have
EnableViewState set to true for both text boxes and it’s not retaining
the values. I have tried variations of ways to fix this (set the
values in a view state object, enable view state on the page as a
whole, etc) and nothing is working.

Am I missing something?

Turns out that the fact the text boxes are disabled is what is causing
the issue. Setting them to be enabled fixed the issue. Weird, not
sure why I wouldn't be able to do that. I have them disabled cause I
wanted them to only be filled by the calendar popup and not manually
entered.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top