Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send custom parameters to user control ascx

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!

like image 843
Arturo Suarez Avatar asked Apr 25 '13 02:04

Arturo Suarez


1 Answers

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" ;

    //...
}
like image 114
mshsayem Avatar answered Oct 25 '22 02:10

mshsayem