Retrieve TextBox.Text Value in Web User Control

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 Sad

 

 


May The Force Be With You ...
0
gianthornet
10/26/2006 7:29:17 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

12 Replies
748 Views

Similar Articles

[PageSpeed] 1

My suggestion would be to use properties...

public string TextBox1Text 
{
    get { return this.TextBox1.Text; }
}
 
0
DevinGoodsell
10/26/2006 7:15:46 PM

Hi DevinGoodsell, Thanks for your reply. BUT I need more option.... [:'(]


May The Force Be With You ...
0
gianthornet
10/27/2006 2:57:49 AM

hi,

how about use findcontrol method?

((TextBox)this.WebUserControl1_1.FindControl("TextBox1")).Text = "Principal

good luck

0
jessjing
10/27/2006 3:19:01 AM

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...

Sad 

 


May The Force Be With You ...
0
gianthornet
10/27/2006 5:33:36 AM

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
Shreekar
10/27/2006 6:29:18 AM

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
jessjing
10/27/2006 6:42:14 AM

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 ? Sad 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
gianthornet
10/27/2006 6:51:07 AM

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.

Sad

 


May The Force Be With You ...
0
gianthornet
10/27/2006 7:30:19 AM
I think we need to see the relevant code to see what is happening.
Shreekar
0
Shreekar
10/27/2006 7:39:08 AM

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
jessjing
10/27/2006 7:41:08 AM

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
DevinGoodsell
10/27/2006 5:50:02 PM

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
ShrinanD
11/21/2007 11:03:20 PM
Reply:

Similar Artilces:

validate Textbox in Web User Control from web form?
ASP.NET 2.0 I have a web user control that contains a textbox.  I need to add some validation (like requiredfieldvalidator, comparevalidator, etc). I would normally add the validator to my web user control by placing the validator next to my textbox.  However, I need the validation message somewhere else on my web form, not near the user control. So how would I associate a validation control on my web form with the text box inside my web user control?  Can this be done; any alternatives out there? Thanks!   The error message should occur wherever you place the vali...

Retreiving a value from a web form within a web user control
Hi  I have a page (web form) that retreives some data from a database. To be more specific: at some point when user clicks a button (in the web form) there is some ID number retreived from a database in code behind. At the same time the Visible property of the nestet web user control is chamged to true. I want than forward the ID to the web user control so that a grid view can load data from a database for that ID. How can I access that data (the ID) within a web user control context nested in that page?  Kind regards   Check this ;ink  http://www.codeproject.com/K...

Filling a textbox on a parent web user control from a child web form
Hi, I currently have a web user control (pf_imageselector.ascx) which is dynamically created (any number of times) on a parent web user control (pf_fillitems.ascx) which in turn has been loaded into a webform (default.aspx). On the user control is a text box called txbSelectedImage and a button. On click of the button run's this code: function OpenChild() { var strImageFile; var WinSettings = "height=580,width=630,status=yes,toolbar=no,menubar=no,location=no"; window.open("pf_stockimage.aspx", null, WinSettings); } Which obviously open a ch...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Web Form and Web User Control
Hello, I have a Web User Control (ascx) that includes a button. This button has an onclick event method. This Web User control is included into a Web Form. (thru LoadControl). However, when I click on the button, the event method is not executed. What should I include in order it works fine? Thanks in advance. GAA. Using Loadcontrol is using dynamic controls and when using dynamic controls you must recreate the same dynamic controls ono postback to econstruct the page control tree. It is best if you do this during the Page PreInit event. How complex are your controls ...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

custom web user control and web form
Guys,          I am trying to develop a context menu control for all of my pages. what i am trying to do is that i want the control to pick a datasource from the markup and then check whether its an xml file or a datatable. I created a class called datasource.   /**************************DataSource Class****************************/  public class DataSource { /// <summary> /// This is to identify unique elements from the markup /// </summary>protected string _ID; /// <summary> /// This will be the Datasource ID e...

Web User Control Not rendering in Web Form
I have created a Web User control that is made up of a Multiview with 2 views inside the Multiview. I have buttons on both views and a gridview on 1 view. My question is when I drop this Web User Control on a Web Form all I see is [MultiView"MultiView1"] and when I view the from in the browser I dont see the Web User Control. I was wondering if someone could please tell me why the Web User Control is not displaying or rendering.     Thanks In Advance Hi, Please check your aspx file for correct reference, like following example: TestControl.ascx:<%@ Control ...

Clearing Web Controls Values from a Web Form
I have a web form and after a user submit it I want to clear the form so that they may submit another entry. I have seen examples in VB of how to loop thru a web form and clear the controls, but I need a C# solution. I have tried the following code, while it does not give me an error, it does not clear the controls on the form. Any suggestions? Thanks! foreach (Control parent in Page.Controls)         {             foreach (Control child in parent.Controls)           ...

web controls and web user control
i have a problem in a web form , I have a webform that contains a web user control which in turn contains a html input form ,the web control events don't fire up ,When I click button ,no effect ,I don't know what is the effect of the html form which is in the web user control on the web controls in the web form ?? can any one help me the web control event should be handle in the code behind page, is the event handler for the button you are clicking registered? You can try double clicking the button, should give you the default btn_click event handler in code behind. Also, make ...

Pass data from Web User Control to Web Form
I have a Web Form that contains a Web User Control. The WUC displays dynamic content. I want to change the TITLE property of the Web Form, based on the contents of the WUC. For example, if the WUC displays information about Horses, I want to change the page title to "HORSES" by passing the string to the parent Web Form. I have tried playing with parameters and such, but I can't remember how I did this in the past. PLEASE HELP!~o0 Spin-Monkey Oo~ The best way to do this is by creating a public property on your web user control and accessing that from your web form. Check ...

Interaction between Web User Control & Web form
Ok, I want to create my first Web User Control which is used for file uploading. It's very simple, consist only of the <asp:FileUpload> and <asp:Button> control. The button has one server side event which is resizing the uploaded image to two different images (stored as byte[] in the cs file). So, my question is how I can send these two arrays of type byte to the Web form where the web user control is inside. I thought it should be possible to write something like this in the Web form:<uc1:FileUploader ID="uploader" runat="server" OnUploaded="recieveImages" />So that means ...

Access SqlDataSource on Web Form from a Web User Control...
Hello, I want to access a SqlDataSource on a Web Form fromout. a Web User Control. To do this, I have in my code behind of the Web User Control the folowing code: DropDownList1.DataSource = (this.Page.FindControl("SqlDataSource3") as SqlDataSource);DropDownList1.DataTextField = "Name;DropDownList1.DataValueField = "NameIDropDownList1.DataBind(); But, the control (ic. SqlDataSource3) is not found. Even other controls like labels and buttons are not found with the FindControl. What am I doing wrong? Thanks Andromedaris     This is not much of a surprise,...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

Web resources about - Retrieve TextBox.Text Value in Web User Control - asp.net.web-forms

Facebook Developers Can Retrieve Users’ Profile Pictures In Different Sizes
Facebook introduced a way for developers to retrieve users’ profile pictures for use within their applications in different sizes, rather than ...

Winston retrieves the news
... food and losing weight. Three months ago, we were told he had lymphosarcoma of the GI tract. On March 10, 2008, Winston was called to go retrieve ...

Gizzard uses a rope to retrieve a submerged gift, 10 second retrieval from noticing the rope - YouTube ...
This is the second attempt, and the second occurrence he has ever seen this contraption. Without the rope, he would probably drown to retrieve ...

Dutch backpacker paid $5 an hour to retrieve golf balls from lakes
A Dutch backpacker claims he was paid as little as $5 an hour to wade through murky ponds and lakes retrieving thousands of lost golf balls. ...

People Are Willing To Go To Extreme Lengths To Retrieve Their Stolen Smartphones
People are willing to pay a ton of money and potentially put themselves in danger to retrieve their stolen smartphones, a new survey has found. ...

Police officer shot at 'very large' shark to retrieve body of swimmer
A policeman who shot a shark in a bid to retrieve the body of a swimmer it had killed says his first bullets disintegrated as they hit the water ...

Divers retrieve body from NSW floodwaters
A woman's body has been retrieved from a submerged car in a creek in Maitland.

Tourist plunges to death from Potts Point rooftop park trying to retrieve football: police
A French tourist who fell to his death from a rooftop park in Potts Point in inner Sydney was attempting to retrieve a football that had gone ...

The art of war: Quest to retrieve what Nazis stole
Susan Fisher Sullam tells of learning her father was a wartime treasure hunter, tracking down what the Nazis had plundered from Holocaust victims. ...

Investigators retrieve more human remains at MH17 crash site in eastern Ukraine but wreckage cannot yet ...
Dutch forensic experts recover further human remains at the crash site of downed flight MH17.

Resources last updated: 11/25/2015 10:09:31 AM