Click here to Skip to main content
Rate this: bad
good
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
Comments
Tadit Dash at 30-Jul-12 16:21pm
   
Can you please post your code ?
dimpledevani at 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 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
good
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
  Permalink  

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

  Print Answers RSS
0 Maciej Los 310
1 OriginalGriff 285
2 Afzaal Ahmad Zeeshan 200
3 Sergey Alexandrovich Kryukov 195
4 BillWoodruff 180
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 31 Jul 2012
Copyright © CodeProject, 1999-2014
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