-
Setting Properties
Here is the solution with code
0
down vote
favorite
i have a UC_Categories.ascx ( UC_1 ) which constraints categoryname . UC_Products.ascx ( UC_2 ) will show products by categoryname. Both of them are in a Page called BookShop.aspx ( Page )
In the Page, when user click a UC_1 (step 1 ) , it will render a UC_2 by categoryname (step2 ). I process step 1 by sending a request with param that is categoryname to Page. Step2 create a new UC_2 ,set Properties value that is categoryname , and execute FillProductByCategoryName method. then add UC_2 to a PlaceHolder in the Page. but i don't show UC_2 .
I need a help or suggest from everyone.
Thank you for reading my question! ps : my english isn't very well.
in the codebehind of the UC2 :
Code:
public void FillProduct()
{
ProductsMN productsMN = new ProductsMN();
if (dlBook == null)
{
dlBook = new DataList();
dlBook.DataSource = productsMN.GetByCategoryName(CategoryName);
dlBook.DataBind();
}
else
{
dlBook.DataSource = productsMN.GetByCategoryName(CategoryName);
dlBook.DataBind();
}
}
public string CategoryName { get; set; }
in the codebehind of the page
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
string categoryName = Request.QueryString["categoryName"] as string;
if (!string.IsNullOrWhiteSpace(categoryName))
{
BookContent.Controls.Clear(); // BookContent : Placeholder
Control c = Page.LoadControl("~/UC/UC_Books.ascx") as UC.UC_Books;
UC.UC_Books ucBook = new UC.UC_Books();
ucBook.CategoryName = categoryName;
ucBook.FillProduct(); //line 10
BookContent.Controls.Add(ucBook); //line 11
}
}
at the PageLoad of the Page, useBook contains data. but in the Page (view ), i don't see data. i think //line11 isn't execute or not true .
-
Re: Setting Properties
For anybody who reads this, I apologize for the subject line. The OP did NOT write that. The question got moved from a different location, since it appears to be ASP.NET, so I had to give it a subject line, and wasn't clear on what would be the best subject title for the question.
-
Re: Setting Properties
Welcome to the forums!
What happens if you add c to BookContent instead of ucBook?
Code:
BookContent.Controls.Add(c);