Click here to Skip to main content
Rate this: bad
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 at 30-Jul-12 16:21pm
Can you please post your code ?
dimpledevani at 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 at 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 at 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
0 OriginalGriff 476
1 Sergey Alexandrovich Kryukov 215
2 CHill60 195
3 Afzaal Ahmad Zeeshan 145
4 TheRealSteveJudge 120
0 Sergey Alexandrovich Kryukov 9,061
1 OriginalGriff 7,920
2 Peter Leow 4,774
3 Kornfeld Eliyahu Peter 3,210
4 Maciej Los 2,176

Advertise | Privacy | Mobile
Web01 | 2.8.150327.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