Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access usercontrol's values from page?

Hi I've created user control named test.ascs with one textbox. Now I added this user control in my default.aspx page. How can i access that textbox value from my default.aspx page?

is there any chance?

like image 603
jestges Avatar asked Apr 09 '10 08:04

jestges


2 Answers

I usually expose the textbox's text property directly in test.ascx code behind like this:

public string Text
{
    get { return txtBox1.Text; }
    set { txtBox1.Text = value; }
}

Then you can get and set that textbox from the code behind of default.aspx like:

usrControl.Text = "something";
var text = usrControl.Text;
like image 69
BritishDeveloper Avatar answered Nov 10 '22 08:11

BritishDeveloper


From your default page try to find the TextBox using your user control.

TextBox myTextBox = userControl.FindControl("YourTextBox") as TextBox;
string text = myTextBox.text;
like image 4
KhanS Avatar answered Nov 10 '22 07:11

KhanS