Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 at 8-Nov-12 9:41am
   
that will do
vijaygsmart at 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 at 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 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 at 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 at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Member 8393790 at 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 at 8-Nov-12 1:38am
   
Well, learn how Web works...
--SA

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



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid