我想註冊(或引用)並以編程方式從後面的代碼處理UserControl。我GOOGLE了很多,但沒有找到一個有用的解決方案來註冊或引用UserControl。如何從後面的代碼以編程方式註冊和處理UserControl?
編輯:
我做了如下:
ASPX頁面:
<%@ Reference Control="~/ucContents.ascx" %>
ASPX頁面背後的代碼:
Control Contents1 = null;
try
{
Contents1 = LoadControl("~/ucContents.ascx");
if (Contents1 != null)
{
((ucContents)Contents1).CatID = Request.QueryString["catid"];
}
}
catch
{ }
我想知道這是有可能在''參考作業(<%@ Reference Control =「〜/ ucContents.ascx」%> '後面的代碼'也是動態的?
你的意思是在運行時動態加載UserControl? – Win 2013-03-18 16:36:49
目前還不清楚這裏要問什麼。請提供更多關於您想要實現的信息,以便我們可以爲您提供幫助。 – magnattic 2013-03-18 16:43:24
我會通知你,你永遠不應該拋棄異常。您將不知道該try/catch塊中引發了哪些異常。 – 2013-03-18 17:42:40