在页面中查找运行时加载的用户控件(ascx)对象(aspx)

时间:2012-08-21 13:14:09

标签: jquery asp.net user-controls ascx

我正在使用jquery-ajax将动态用户控件(ascx)加载到页面(aspx)。运行, 我想要一个已在页面中加载的用户控件实例。 我能怎么做? 感谢

       function funDersinSubeleriniGoster(programDersGrubDersId) {
            $.blockUI();
            var ControlName = "OgrenciUserControls/KayitYenileme/DersSubeleriControl.ascx";
            $.ajax({
                type: "POST",
                url: "KayitYenileme.aspx/DersinSubeleriniYukle",
                data: "{controlName:'" + ControlName + "',programDersGrubDersId:'" + programDersGrubDersId + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    $.unblockUI();
                    //$('#dialogDersKayitPopup').html(response.d).dialog({ resizable: false, height: 600, width: 800, modal: true });
                },
                failure: function (msg) {
                    $.unblockUI();
                    //$('#dialogDersKayitPopup').html(msg).dialog({ resizable: false, height: 600, width: 800, modal: true });
                }
            });

            return false;

        }

aspx Page

[WebMethod]
public static void DersinSubeleriniYukle(string controlName, int programDersGrubDersId)
{

}

private void UserControlsFind()
{
    //I want to have user controls instance.
}

2 个答案:

答案 0 :(得分:0)

如果要传递对象名称(DersinSubeleriniYukle子句中的controlName),则可以从服务器端找到控件:

dim myControl as yourUserControlType 
myControl = me.findControl(controlName)

您可能需要在ascx页面中添加引用,如下所示:

<%@ Reference Control="~/user_controls/yourUserControlType.ascx"%>

答案 1 :(得分:0)