I am gonna pass some texts and images address from aspx file to ascx file with page.loadControl function.
in my aspx file I have this line code :
form.Controls.Add(page.LoadControl("~/Controls/Shared/NoResults.ascx"));
How can I pass my data with page.loadControl which is located in aspx to userControl ? and How can I use in ascx?
internal string RenderList() { ConstructGrid(); SetSort(); var page = new Page() { EnableViewState = false }; var form = new System.Web.UI.HtmlControls.HtmlForm(); page.Controls.Add(form); if (Data != null && Data.PageInfo != null && Data.PageInfo.TotalRecords > 0) { form.Controls.Add(this); DataBind(); } else form.Controls.Add(page.LoadControl("~/Controls/Shared/NoResults.ascx")); return ControlLoader.RenderCustomControl(page); }
You have to expose a public property in the .ascx file and assign the desired values to the respective properties.
internal string RenderList()
{
ConstructGrid();
SetSort();
var page = new Page() { EnableViewState = false };
var form = new System.Web.UI.HtmlControls.HtmlForm();
page.Controls.Add(form);
if (Data != null && Data.PageInfo != null && Data.PageInfo.TotalRecords > 0)
{
form.Controls.Add(this);
DataBind();
}
else
var noResultsControl = (Page.LoadControl("~/Controls/Shared/NoResults.ascx") as NoResults)
noResultsControl.PropertyOne = "Sample" ;
form.Controls.Add(noResultsControl);
return ControlLoader.RenderCustomControl(page);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.