| Author: Vidhya 26 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
How to call user controls value (like Textbox, button, checkbox etc.) in aspx page.
When you use usercontrols in your form it’s very easy to get that user control value in your form.
I am taking one example you are creating one Usercontrol that have two textbox with User Id and Password. And this usercontrols you can use in your form either Load that control run time or Drag that control in your form design time.
1) Create one usercontrol name: Test.ascx That have one panel on design time name: Panel1 Call this method (AddControls) in Page_Load() event in your UserContorl Page (Test.ascx)
public void AddControls() { Label lblUserName; Label lblPassword; TextBox txtUserName; TextBox txtPassword;
lblUserName = new Label(); lblUserName.Text ="User Name : "; txtUserName = new TextBox(); txtUserName.ID="txtUserId1"; lblPassword = new Label(); lblPassword.Text="Password : "; txtPassword = new TextBox(); txtPassword.ID="txtPassword1"; txtPassword.TextMode = System.Web.UI.WebControls. TextBoxMode.Password;
Panel1.Controls.Add(lblUserName); Panel1.Controls.Add(txtUserName); Panel1.Controls.Add(lblPassword); Panel1.Controls.Add(txtPassword); }
2) Create one form name: TestUserControls.aspx now There are two ways to use this usercontrol in your form(TestUserControls.aspx)
a) Drag this usercontrol in your form
OR
b) Load this user control in Page_Load() event in your form (TestUserControls.aspx) where you are using this control.
|
| Author: Sabu C Alex 28 Jul 2008 | Member Level: Gold | Rating: Points: 3 |
hi
create properties for setting and getting values to Textboxes in usercontrol. So that you can assign values to textbox using this properties from codebehind.
|