Click here to Skip to main content
11,928,078 members (26,246 online)
Rate this:
Please Sign up or sign in to vote.
See more: SharePoint WebParts
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 30-Jul-12 0:47am
Tadit Dash 30-Jul-12 16:21pm
Can you please post your code ?
dimpledevani 31-Jul-12 0:52am

Protected Overrides Sub CreateChildControls()


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


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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151126.1 | Last Updated 31 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100