Hi,
I have a TextBox in a web usercontrol, I load the web usercontrol on a panel of the web form.
My goal is to retrieve the value of the textbox after I entered any character on it. I want to transfer the textbox value in a Session.
Can you help me guys
May The Force Be With You ...
![]() |
0 |
![]() |
My suggestion would be to use properties...
public string TextBox1Text { get { return this.TextBox1.Text; } }
![]() |
0 |
![]() |
Hi DevinGoodsell, Thanks for your reply. BUT I need more option.... [:'(]
May The Force Be With You ...
![]() |
0 |
![]() |
hi,
how about use findcontrol method?
((TextBox)this.WebUserControl1_1.FindControl("TextBox1")).Text = "Principal
good luck
![]() |
0 |
![]() |
Hi jessjing, still not working.
After I type any character on the textbox, then I click the save button on the web user control, the page made a refresh and the value of the textbox disappeared. I need to get textbox value even if the page made a refresh...
![]()
May The Force Be With You ...
![]() |
0 |
![]() |
In the custom web control, expose a property called TextboxText (or something) as the first reply suggested. On click of the button in the custom web control, read the value of the text box, assign it to the TextboxText property OR get the current Session and add it to the current session collection
On load of the custom web control, read the value from session, and if exists, assign it to the TextboxText property and the Text box control.
Hope this helps.
Shreekar
![]() |
0 |
![]() |
hi,
sorry to hear that.
how about Add a public method to the usercontrol that sets its textbox's text to a
given value. Then call this method from your page and pass it the new text.wish helpful
![]() |
0 |
![]() |
hi guys,
The new encoded value on the textbox.text does not disappear only if I FIRST click the save button twice before encoding any character. from there, it retrieves the value of the textbox.text. So, the web usercontrol needs to be refreshed twice ?
I think it must be save during keypress. What if I use javascript for the onkeypress event? but I need code for javascript.
May The Force Be With You ...
![]() |
0 |
![]() |
Hi Guys,
to be clear, here are the scenarios,
1. Load the web usercontrol on the panel of the web form. The web usercontrol includes the textbox and save button.
2. I enter any character on the textbox and then click save button to assign the value on textbox.text to a session.
3. Afterwhich, the page made a refresh, and then the value on the textbox.text is empty.
4. When I click the save button twice, and then enter any character on the textbox, and then click the save button, the value on the texbox is retained. and I can assign the value to a session.
May The Force Be With You ...
![]() |
0 |
![]() |
I think we need to see the relevant code to see what is happening.
Shreekar
![]() |
0 |
![]() |
hi,
of course the web usercontrol doesn't need to be refreshed twice.
(TextBox)TextBoxControl1.FindControl ("TextBox1")).Text works fine on my project.
your problem is a little odd.
![]() |
0 |
![]() |
I do agree as suggested earlier we need some releveant code. I have a question for you though, what's the purpose in you using a session and what's the purpose of this textbox? Another question is this web user control added dynamically or is it static? If static what are you assigning to the textbox in the onload event? You see it shouldn't loose it's value if it's static. With the regard to the button save being held inside the user control with the textbox, what i would do is add a delegate or an extracted event on that control such as save and then handle the event externally outside of the webusercontrol. On top of this i would have a property set up to allow me access to the textbox and viola. You can now access the text within the external onsave event. IE:
---- The Inside of the Web User Control
public event EventHandler Save; public TextBoxValue { get { return this.textbox1.Text;} } protected void btnSave_Click(object sender, EventArgs e) { if (Save != null) Save(object,e); }------ Inside the ASPX Page
protected void WebUserControl_Save(object sender, EventArgs e) { string s = WebUserControl.TextBoxValue; // Gets the value from the Textbox }Hope that helps....
![]() |
0 |
![]() |
1) Use ASP.Net TextBox Server Control instead of Standard HTML TextBox control.
If it does not solve your problem, try adding this in the Page_Load event
2) textBoxName.Attributes.Add("value", textBoxName.Text) -- (here, textBoxName is the name of the textBox you want to retain text value for)
I hope this helps.
Shrinand Vyas
University of Houston
![]() |
0 |
![]() |