Link to home
Start Free TrialLog in
Avatar of manud30
manud30

asked on

Regarding View state

I have a textbox in an aspx page . I am creating this textbox dynamically in my code behind
Iam not getting the value of the textbox in the page load . Is this because the control is being generated
dynamically . Is there a solution to this ?
Avatar of mondayblueboy
mondayblueboy


Hi

Did you create the textbox something like this,

Dim txt As New TextBox
txt.Width = New Unit("100%")
txt.Visible = True
txt.Attributes.Add("runat", "server")
txt.EnableViewState = True
txt.ID = "MyTextBox"
ASKER CERTIFIED SOLUTION
Avatar of GoodJun
GoodJun

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of manud30

ASKER

Any how the Textbox1's value will be stored in viewstate(asp.net does this . Doesn't it?) . can I access this value in page load before control is created and assign this value to the textbox control after its creation ? I mean to say decode view state and find this control's value from it.
in your postback event handler(eg, button_click()):
viewstate("myTextbox1")=mytextbox1.text
'that's all the code you need to store it in viewstate


can I access this value in page load before control is created and assign this value to the textbox control after its creation ? I mean to say decode view state and find this control's value from it.
Yes. The value in view state is there (before create the 2nd control, it is put there in the 1st control)
textbox1-->viewstate("myvalue")-->request send to server-->server create response (include create textbox2)-->assign viewstate("myvalue") to textbox2
Avatar of manud30

ASKER

How to get the value of the textfield stored by asp.net from view state
mytextbox1.text=viewstate("myvalue")
Avatar of manud30

ASKER

Iam not going to put the textfield value in viewstate as this is done by asp.net . But against what key value does asp.net put the textbox value , which can be used for retrieving the value .
You still didn't get it.
Put the value to viewstate manully and then you can get it back manully. If asp.net put it automatically, you can wish your luck to retrieve it back.
Avatar of manud30

ASKER

if asp.net doesn't do it . When the same control is created in aspx page (not dynamically) . How does it user typed value is obtained in page_load . Since iam creating the control dynamically this is not happenning? Why ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Learned
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: GoodJun {http:#9546492} & mondayblueboy {http:#9572915}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer