
Asp.Net Web Forms, can be considered as a legacy technology, but somehow it is still widely used in the industry ( as for today date 2018 ). Here is where we may find an article about creating a User Control that is useful for guidance if we encounter such solution.
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 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 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 "; | |
} |
Legacy Published on : 17-Dec-2014
Ref no : DDN-L-WPUB-00001
About Author

Comments
Post a Comment