如何从用户控件添加对母版页脚本管理器的引用?

发布于 2024-12-09 10:01:32 字数 569 浏览 1 评论 0原文

我有一个 ScriptManager 添加到我的 MasterPage 中;

 <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true" />

我有一个放置在母版页上的 Web 用户控件。

在 Web 用户控件内部,我想使用 PageMethods,但它抱怨 PageMethods 未定义。

 function ddlSqlConnections_SelectedIndexChange(selectedValue) {

        PageMethods.OnSelectedIndexChanged(selectedValue);
        location.reload(true);
    }

我向用户控件添加了一个新的 ScriptManager,它抱怨一页上只能存在一个脚本管理器,所以

基本上如何从用户控件添加对母版页脚本管理器的引用?

好像不太可能吧?

谢谢,

I have a ScriptManager which is added to my MasterPage;

 <telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnablePageMethods="true" />

I have a Web User Control which is placed on the master page.

Inside the web user control, I'd like to use PageMethods but it complains that PageMethods is not defined.

 function ddlSqlConnections_SelectedIndexChange(selectedValue) {

        PageMethods.OnSelectedIndexChanged(selectedValue);
        location.reload(true);
    }

I added a new ScriptManager to the user control and it complained that only one scriptmanager can exist on one page so

basically how to add a reference to the master page script manager, from the user control?

It doesn't seem to be possible?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明天过后 2024-12-16 10:01:32

使用常规的 ScriptManager 而不是 RadScriptManager:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

Use a regular ScriptManager instead of the RadScriptManager:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
青朷 2024-12-16 10:01:32

我的结论是,使用 Web 用户控制页面方法是不可能的,我使用 AJAX 和 Web 服务来代替:

$('.ddlSqlConnections').change(function (control) {

            var selectedValue = control.currentTarget.value;            
            if (selectedValue == 0) {
                return;
            }

            $.ajax({
                type: "POST",
                url: "AdminService.asmx/AdminConnectionsOnSelectedIndexChanged",
                data: "{uniqueName: " + selectedValue + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {                                        
                    location.reload(true);
                },
                error: function (msg) {
                    alert('failed to send a web service request; please contact the administrator.')                    
                }
            });
        });

My conclusion was it's not possible with a Web User Control Page Method and I used AJAX with web service instead:

$('.ddlSqlConnections').change(function (control) {

            var selectedValue = control.currentTarget.value;            
            if (selectedValue == 0) {
                return;
            }

            $.ajax({
                type: "POST",
                url: "AdminService.asmx/AdminConnectionsOnSelectedIndexChanged",
                data: "{uniqueName: " + selectedValue + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {                                        
                    location.reload(true);
                },
                error: function (msg) {
                    alert('failed to send a web service request; please contact the administrator.')                    
                }
            });
        });
雪花飘飘的天空 2024-12-16 10:01:32

您可以尝试从用户控件调用母版页中的方法。

 Page.GetType().InvokeMember("MethodName", BindingFlags.InvokeMethod, null, this.Page, new object[] { });

You could try to Invoke a method in your masterpage from your userconrol.

 Page.GetType().InvokeMember("MethodName", BindingFlags.InvokeMethod, null, this.Page, new object[] { });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文