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?
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?
From your default page try to find the TextBox using your user control.
TextBox myTextBox = userControl.FindControl("YourTextBox") as TextBox;
string text = myTextBox.text;
If this is the purpose of the control, then create a public property on your user control that exposes this value, you can then access that from your page:
string textBoxValue = myUserControl.GetTheValue;
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;