Click here to Skip to main content
15,868,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,


I have a textbox control and a button control in a webpart. when i click the button control(postback) the text in the textbox control is inserted in my database and then the textbox should be cleared. In my case the text in the control is not getting cleared.
I am generating the above said controls dyanamically in the CreateChildControls method. I tried setting the enable viewstate for this control to false but that does not work.
what should be done to overcome the issue?

Thanks in advance..
Posted
Comments
Can you please post your code ?
dimpledevani 31-Jul-12 0:52am    
code:



Protected Overrides Sub CreateChildControls()
Try



Controls.Clear()

lblConfirmation = New Label With
{
.ID = "lblConfirmation",
.EnableViewState = True
}

lblReason = New Label With
{
.ID = "lblreason",
.Text = "Reason"
}

'txtReason = New InputFormTextBox With 'commented for local testing and wrote the below line

txtReason = New TextBox With
{
.ID = "txtReason",
.TextMode = TextBoxMode.MultiLine,
.EnableViewState = False,
.Width = Unit.Percentage(100),
.Height = Unit.Pixel(60),
.Wrap = True
}
end sub


I am creating textboxes in createchildcontrols event and have one button on click event of which I am writing

sReason=txtReason.Text 'sreason is a class variable

txtReason.Text=""


While debugging I can see the value as "" in watch window but in design it still there
arunraju 31-Jul-12 1:10am    
// use this under page load
if (ViewState[this.ClientID.ToString() + "addgoal_loaded"] == null)
{


ViewState["username"] = text1.text
ViewState["password"] = text2.text




}

//in the button click event

ViewState[this.ClientID.ToString() + "addgoal_loaded"] = true;

text1.text = (string)ViewState["username"];
text2.text = (string)ViewState["password"];
u can reassign the state value to textbox

i think it ll help you
dimpledevani 31-Jul-12 2:21am    
Thank you very much for replying,But I found the issue and solved it myself.

1 solution

There was some problem with Page.Response in my case, So i just used Page.response.Clear and now its working fine.Thank you once again
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900