weixin_33728268 2010-12-10 21:47 采纳率: 0%
浏览 47

使用多个ScriptManager

I have an asp.net 4.0 app where all pages use a master page. I have several dynamic aspects going on in both the masterpage and the child of the pages. For both I'd like to be able to use the built in Microsoft ScriptManager with this kind of pattern:

Code behind:

using System;
using System.Web;
using System.Web.Services;

namespace MyApp.Secure
{
    public partial class myPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        [WebMethod]
        public static string GetString()
        {
            return "abc";
        }
    }
}

Then in the page content itself:

<script>
   PageMethods.GetString(OnSucceeded, OnFailed);

    function OnSucceeded(rslt) {
        alert('cool,worked.');
    }

    function OnFailed(error) {
        alert('ooops,failed.');
    }

</script>

So, to use this technique I'd like to expose static [WebMethod]'s in both my masterpage and my child page. My question is, how do I manage this with a ScriptManager? From my understanding, I need to have a ScriptManager within a form tag (why?) so that a javascript library is added to allow me to use the PageMethods object. Should I just create one ScriptManager in my masterpage and tuck it in a useless form tag in the masterpage? Will that ScriptManager pickup the [WebMethod] functions in my child page? And what about that form tag: I know I can only have one form runat='server' tag so how would I manage a that with other forms I need within my masterpage? Like my little form that wraps my search function at the top of the page?

Thanks

  • 写回答

3条回答 默认 最新

  • weixin_33717117 2010-12-10 21:54
    关注

    A ScriptManager on your masterpage will suffice (yes in the form tag). The on pages that inherit your master, place a scriptmanagerproxy control.

    I think typically people use one form tag, and then for form buttons, the postback handles the action that is appropriate - like redirecting to a search page. I'm not a fan of this method, why handle a postback when you just want to redirect to a search page with a querystring. I've used javascript mostly get get around it, either on button click change the form action to whatever is appropriate, or just override the submit button type all together and have javascript build your new url and change the location bar

    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误