I need to use user controls (.ascx) on a page, it's a related post user control based in 2 parameters:
1. Current post
2. Relation type
the page needs to have 3 different instances of this control, each having the same Current post parameter, but different relation type (title, author, genre).
The 1st parameter I can get it through url, but what about the second parameter?
I've been googling for a while but i haven't found an answer yet. How can I pass the second parameter so the control can load the information based on these parameters? I'd rather not to create a control for each parameter, else would be better to build no user control but direct into code :( Thanks!
Create public properties of the user-control like:
public partial class SampleUC : UserControl
{
public string CurrentPost {get;set;}
public string RelationType {get;set;}
//...
//...
}
Assign those from the page using it either from markup like:
<%@ Register TagPrefix="cc" TagName="SampleUC" Src="SampleUC.ascx" %>
...
...
<cc:SampleUC id="myUC" runat="server" CurrentPost="Sample Post Title" RelationType="Title" />
or from code-behind (of the page using it):
protected void Page_Load(object sender, EventArgs e)
{
//...
myUC.CurrentPost = "Sample Post Title";
myUC.RelationType = "Title" ;
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With