How to pass a parameter to a user control?

Platform: ASP.NET| Category: User Controls

Create a User Control
Below Code goes in User Control


<asp:ImageButton id='ImageButton1' runat='server'></asp:ImageButton>

Create a property called source
VB.NET


Public Property source() As String
	Get
		Return ImageButton1.ImageUrl
	End Get
	Set(ByVal Value As String)
		ImageButton1.ImageUrl = Value
	End Set
End Property

C#


public string source 
{
	get 
	{
		return ImageButton1.ImageUrl;
	}
	set 
	{
		ImageButton1.ImageUrl = value;
	}
}

Now in your webform:
Drag and drop User Control and set the source property.


<uc1:UCImageButton source='b2346.jpg' id='UCImageButton1' runat='server'></uc1:UCImageButton>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.