Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I added the user control dynamically in asp.net(which contain 3 textboxes) using Jquery,
how to get textbox value of user control in aspx.cs file.

After dynamically show the user control page in aspx page, I have a button in aspx page when I click the button I need to get the value of textbox in aspx.cs page
Posted

The best way to do that would be to create a property for each text box inside the user control as:

C#
public string TextBox1Value
{
 get
 {
  return textbox1.text;
 }
}

and from your page you can directly do:

C#
usercontrol1.TextBox1Value;

this will contain the textbox value.
 
Share this answer
 
Comments
adriancs 8-Nov-12 9:41am    
that will do
vijaygsmart 8-Mar-13 2:14am    
my problem. 1st page i get 1st row record from grid and send the row record to next page and it show . then i cant update it . i found update - textbox.text not editable
Hi,

Create property of the textbox expose them and then access form the calling page.

Hope this help you.
 
Share this answer
 
Comments
Member 8393790 8-Nov-12 1:52am    
thanks,

When I use the Property for textbox in ascx file.
For Example:
public string College
{
get { return txtCollege.Text; }
set { txtCollege.Text = College; }
}

public string Percentage
{
get { return txtPercentage.Text; }
set { txtPercentage.Text = Percentage; }
}

public string Year
{
get { return txtYear.Text; }
set { txtYear.Text = Year; }
}
Is this correct? When I try to access these property from aspx.cs page using class, I got error I can't get the value of text box. If there is any link or source
for this
 
Share this answer
 
Comments
Member 8393790 8-Nov-12 1:33am    
Thanks for ur reply..

I can access the System.Web.UI.WebControls TextBox directly, But I can't access the User Control's textbox in aspx.cs file.. Because user control was loaded dynamically in aspx page.
Sergey Alexandrovich Kryukov 8-Nov-12 1:38am    
Well, learn how Web works...
--SA
In C# WINDOWS

First go to user control,then for all textbox change access specifier private to public, if u r accessing them through another form or control,if not then no need to do public.
then
C#
string a,b,c;
a=UserControlName.TextBox1.Text;
b=UserControlName.TextBox2.Text;
c=UserControlName.TextBox3.Text;
 
Share this answer
 
v2
Comments
Member 8393790 8-Nov-12 2:02am    
In where I have to give access specifier for text box. using get set properety?
After using
public string College
{
get { return txtCollege.Text; }
set { txtCollege.Text = College; }
}
this, I cant use UserControlName.College; please help
StackQ 8-Nov-12 2:27am    
AT UserControl right click on every textbox then-go to properties then-see Modifiers change it to public
fjdiewornncalwe 8-Nov-12 9:22am    
My 1: It is very bad practice to expose the control itself as a public member. The proper way to do this is Solution 4 by Rahul.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900