Back - Web Applications> Web Forms - Legacy
Adding a new user control Example .
1. Add new user control
2. Add Child Control
3. Add Desired Code behind algorithm
4. Drag user control from solution explorer to desired web page .
5. Baam .. now the user control is there .
Consideration
1. Accessing the properties .
- Add a public properties on the user control code behind . And Assign desired task on page_load .
example :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Usercontrol Code Behind | |
public partial class MyUserControl : System.Web.UI.UserControl | |
{ | |
public string ButtonText { get; set; } | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
Button1.Text = ButtonText; | |
} | |
} | |
//Web Page Code Behind | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
UserControlLogin.ButtonText = " test "; | |
} |
We may use it like this too
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//user control code behind .. | |
public partial class LoginUserControl : System.Web.UI.UserControl | |
{ | |
public string ButtonTex | |
{ | |
set { Button1.Text = value } | |
} | |
} | |
//with no need code at the page_load method | |
//Web Page Code Behind : | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
LoginUserControlAtTop.ButtonText = " test "; | |
} |
Back - Web Applications> Web Forms - Legacy
Published on : 27-Dec-2018
Legacy Published on : 17-Dec-2014
Ref no : DDN-L-WPUB-00001
About Author

Comments
Post a Comment