Click here to Skip to main content
12,953,223 members (78,513 online)
Rate this:
 
Please Sign up or sign in to 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 7-Nov-12 18:43pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

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

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

and from your page you can directly do:

usercontrol1.TextBox1Value;

this will contain the textbox value.
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

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

Hope this help you.
  Permalink  
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
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.
   
Well, learn how Web works...
--SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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
string a,b,c;
a=UserControlName.TextBox1.Text;
b=UserControlName.TextBox2.Text;
c=UserControlName.TextBox3.Text;
  Permalink  
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
01010RAJ 8-Nov-12 2:27am
   
AT UserControl right click on every textbox then-go to properties then-see Modifiers change it to public
Marcus Kramer 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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 7 Apr 2015
Copyright © CodeProject, 1999-2017
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