E
Elroyskimms
I have an aspx page, which loads a custom usercontrol (UCtrlA). UCtrlA
has a drop down list, and depending on what is selected in UCtrlA's
drop down list ("Create New" or "Edit Existing"), another usercontrol
is added (dynamically) to UCtrlA through LoadControl (UCtrlNew or
UCtrlEdit).
UCtrlNew has some textboxes and a submit button. When the submit button
is clicked, the contents of the textboxes are combined and saved in a
text file on the server.
UCtrlEdit has the same basic controls as UCtrlNew (textboxes and an
update button) and is supposed to be used to read the existing text
file (created by UCtrlNew) and re-populate the textboxes with their
original values. The update button should combine the textbox values
and overwrite the original text file on the server, thus updating it.
When UCtrlEdit is loaded (OnLoad), the values are read properly from
the text file and are loaded into their appropriate textboxes. However,
when I click the update button the contents of the textboxes are
returned to their original values (as read from the textfile). For
example, textfile reads "Original text" and when UCtrlEdit loads, the
textbox shows "Original text". I change the value to be "Modified text"
and click submit. When the postback is complete, the textbox shows
"Original text".
If this were a web page, the solution is to only read the textfile when
the page is not being loaded via postback. However, this is a dynamic
control so the control is first loaded on a postback and every
interaction with the control will be done through a postback. Somehow,
I need to access the modified contents of the textbox. I've read in
various places that I should populate the textbox in the OnInit
procedure but that has not resolved the problem (perhaps I am doing it
wrong?). When the Update button is clicked, are the contents of the
modifed textboxes stored in ViewState or does ViewState only contain
the original values read from the textfile? If the modified text is in
ViewState, how do I search ViewState for the contents of a specific
textbox? If ViewState is not the answer, how do I access the modified
version of a textbox after postback in a dynamic control?
has a drop down list, and depending on what is selected in UCtrlA's
drop down list ("Create New" or "Edit Existing"), another usercontrol
is added (dynamically) to UCtrlA through LoadControl (UCtrlNew or
UCtrlEdit).
UCtrlNew has some textboxes and a submit button. When the submit button
is clicked, the contents of the textboxes are combined and saved in a
text file on the server.
UCtrlEdit has the same basic controls as UCtrlNew (textboxes and an
update button) and is supposed to be used to read the existing text
file (created by UCtrlNew) and re-populate the textboxes with their
original values. The update button should combine the textbox values
and overwrite the original text file on the server, thus updating it.
When UCtrlEdit is loaded (OnLoad), the values are read properly from
the text file and are loaded into their appropriate textboxes. However,
when I click the update button the contents of the textboxes are
returned to their original values (as read from the textfile). For
example, textfile reads "Original text" and when UCtrlEdit loads, the
textbox shows "Original text". I change the value to be "Modified text"
and click submit. When the postback is complete, the textbox shows
"Original text".
If this were a web page, the solution is to only read the textfile when
the page is not being loaded via postback. However, this is a dynamic
control so the control is first loaded on a postback and every
interaction with the control will be done through a postback. Somehow,
I need to access the modified contents of the textbox. I've read in
various places that I should populate the textbox in the OnInit
procedure but that has not resolved the problem (perhaps I am doing it
wrong?). When the Update button is clicked, are the contents of the
modifed textboxes stored in ViewState or does ViewState only contain
the original values read from the textfile? If the modified text is in
ViewState, how do I search ViewState for the contents of a specific
textbox? If ViewState is not the answer, how do I access the modified
version of a textbox after postback in a dynamic control?