Postback nightmares

  • Thread starter Thread starter Doogie
  • Start date Start date
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?
 
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?
 
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.
 
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.
 
Back
Top