亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

UpdatePanel和自定義控件中的客戶端腳本

2019-11-18 16:48:15
字體:
來源:轉載
供稿:網友

Over the last few weeks since MS Ajax Beta rolled around I’ve been getting a number of reports of the wwHoverPanel control running into some PRoblems when running in combination with MS Ajax. The controls themselves don’t interfere with MS AJAX directly, but if you’re sticking the controls inside of an AJAX UpdatePanel() there’s a problem as the script code that the controls spit out don’t get properly generated into the callback generated updates. With the script code missing the controls still work but exhibit some unexpected behaviors. For example a hover panel placed into an update panel will lose it’s positioning in many cases and instead of popping up at the current mouse cursor position will pop up at the border of the container control it lives in.

 

The problem is that Microosft decided in MS AJAX Beta to go with a completely separate script generation engine which is driven through the ScriptManager control. The MS Ajax ScriptManager mimics many of the ClientScript object’s methods, but provides them as static methods (thankfully! without that we’d be really screwed).

 

So methods like RegisterClientScriptBlock, ResgisterClientScriptResources – anything that deals with getting script code into the page have related static methods in ScriptManager. The ScriptManager methods pass in the Control as an additional first parameter but otherwise mimic the existing ClientScriptManager.

 

This new behavior puts existing controls into a bind though – if code uses ClientScriptManager then UpdatePanels will not be able to see the script code (if it needs updating in a callback). But at the same time the control developer can’t make the assumption that the MS Ajax ScriptManager actually exists.

 

The end result of all of this is that it’s not exactly straight forward to deal with this mismatch and what needs to happen is that a wrapper object needs to be created that can decide which control to use. The wrapper needs to deal with deciding whether MS Ajax is available in the application and if it is, using Reflection to access the ScriptManager to write out any script code.

 

I can’t take credit for this though: Eilon Lipton posted about this issue a while back and his code really was what I needed to get this off the ground, I just wrapped the thing up into a ClientScriptProxy object that I used on a handful of controls. I basically added a handful of the ClientScript methods that I use in my applications. Here’s the class:

 

[*** code updated: 12/12/2006 from comments *** ]

 

/// <summary>

/// This is a proxy object for the Page.ClientScript and MS Ajax ScriptManager

/// object that can Operate when MS Ajax is not present. Because MS Ajax

/// may not be available accessing the methods directly is not possible

/// and we are required to indirectly reference client script methods through

/// this class.

///

/// This class should be invoked at the Control's start up and be used

/// to replace all calls Page.ClientScript. Scriptmanager calls are made

/// through Reflection

/// </summary>

public class ClientScriptProxy

{

    private static Type scriptManagerType = null;

 

    // *** Register proxied methods of ScriptManager

    private static MethodInfo RegisterClientScriptBlockMethod;

    private static MethodInfo RegisterStartupScriptMethod;

    private static MethodInfo RegisterClientScriptIncludeMethod;

    private static MethodInfo RegisterClientScriptResourceMethod;

    //private static MethodInfo RegisterPostBackControlMethod;

    //private static MethodInfo GetWebResourceUrlMethod;

   

    ClientScriptManager clientScript;

 

    /// <summary>

    /// Determines if MsAjax is available in this Web application

    /// </summary>

    public bool IsMsAjax

    {

        get

        {

            if (scriptManagerType == null)

               CheckForMsAjax();

 

            return _IsMsAjax;

        }

    }

    private static bool _IsMsAjax = false;

 

   

    public bool IsMsAjaxOnPage

    {

        get

        {

            return _IsMsAjaxOnPage;

        }

    }

    private bool _IsMsAjaxOnPage = false;

 

 

    /// <summary>

    /// Current instance of this class which should always be used to

    /// access this object. There are no public constructors to

    /// ensure the reference is used as a Singleton.

    /// </summary>

    public static ClientScriptProxy Current

    {

        get

        {

                return

                ( HttpContext.Current.Items["__ClientScriptProxy"] ??

                (HttpContext.Current.Items["__ClientScriptProxy"] =

                    new ClientScriptProxy(HttpContext.Current.Handler as Page)))

                as ClientScriptProxy;

        }

    }

 

 

    /// <summary>

    /// Base constructor. Pass in the page name so we can pick up

    /// the stock the

    /// </summary>

    /// <param name="CurrentPage"></param>

    protected ClientScriptProxy(Page CurrentPage)

    {

        this.clientScript = CurrentPage.ClientScript;

    }

 

    /// <summary>

    /// Checks to see if MS Ajax is registered with the current

    /// Web application.

    ///

    /// Note: Method is static so it can be directly accessed from

    /// anywhere

    /// </summary>

    /// <returns></returns>

    public static bool CheckForMsAjax()

    {

        scriptManagerType = Type.GetType("Microsoft.Web.UI.ScriptManager, Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", false);

        if (scriptManagerType != null)

        {

            _IsMsAjax = true;

            return true;

        }

 

       _IsMsAjax = false;

       return false;

    }

 

    /// <summary>

    /// Registers a client script block in the page.

    /// </summary>

    /// <param name="control"></param>

    /// <param name="type"></param>

    /// <param name="key"></param>

    /// <param name="script"></param>

    /// <param name="addScriptTags"></param>

    public void RegisterClientScriptBlock(Control control, Type type, string key, string script, bool addScriptTags)

    {

        if (this.IsMsAjax)

        {

            if (RegisterClientScriptBlockMethod == null)

                RegisterClientScriptBlockMethod = scriptManagerType.GetMethod("RegisterClientScriptBlock");

 

            RegisterClientScriptBlockMethod.Invoke(null, new object[5] { control, type, key, script, addScriptTags });

        }

        else

            this.clientScript.RegisterClientScriptBlock(type, key, script, addScriptTags);

    }

 

    /// <summary>

    /// Registers a startup code snippet that gets placed at the bottom of the page

    /// </summary>

    /// <param name="control"></param>

    /// <param name="type"></param>

    /// <param name="key"></param>

    /// <param name="script"></param>

    /// <param name="addStartupTags"></param>

    public void RegisterStartupScript(Control control, Type type, string key, string script, bool addStartupTags)

    {

        if (this.IsMsAjax)

        {

            if (RegisterStartupScriptMethod == null)

                RegisterStartupScriptMethod = scriptManagerType.GetMethod("RegisterStartupScript");

 

            RegisterStartupScriptMethod.Invoke(null, new object[5] { control, type, key, script, addStartupTags });

        }

        else

            this.clientScript.RegisterStartupScript(type, key, script, addStartupTags);

 

    }

 

    /// <summary>

    /// Registers a script include tag into the page for an external script url

    /// </summary>

    /// <param name="control"></param>

    /// <param name="type"></param>

    /// <param name="key"></param>

    /// <param name="url"></param>

    public void RegisterClientScriptInclude(Control control, Type type, string key, string url)

    {

        if (this.IsMsAjax)

        {

            if (RegisterClientScriptIncludeMethod == null)

                RegisterClientScriptIncludeMethod = scriptManagerType.GetMethod("RegisterClientScriptInclude");

 

            RegisterClientScriptIncludeMethod.Invoke(null, new object[4] { control,  type, key, url });

        }

        else

            this.clientScript.RegisterClientScriptInclude( type, key, url);

    }

 

 

    /// <summary>

    /// Adds a script include tag into the page for WebResource.

    /// </summary>

    /// <param name="control"></param>

    /// <param name="type"></param>

    /// <param name="resourceName"></param>

    public void RegisterClientScriptResource(Control control, Type type, string resourceName)

    {

        if (this.IsMsAjax)

        {

            if (RegisterClientScriptResourceMethod == null)

                RegisterClientScriptResourceMethod = scriptManagerType.GetMethod("RegisterClientScriptResource");

 

            RegisterClientScriptResourceMethod.Invoke(null, new object[3] { control, type, resourceName });

        }

        else

            this.clientScript.RegisterClientScriptResource(type,resourceName);

    }

 

 

    public string GetWebResourceUrl(Control control, Type type, string resourceName)

    {

        //if (this.IsMsAjax)

        //{

        //    if (GetWebResourceUrlMethod == null)

        //        GetWebResourceUrlMethod = scriptManagerType.GetMethod("GetScriptResourceUrl");

 

        //    return GetWebResourceUrlMethod.Invoke(null, new object[2] { resourceName, control.GetType().Assembly }) as string;

        //}

        //else

        return this.clientScript.GetWebResourceUrl(type, resourceName);

    }

 

}

 

The code basically checks to see whether the MS Ajax assembly can be accessed as a type and if so assumes MS Ajax is installed. This is not quite optimal – it’d be better to know whether a ScriptManager is actually being used on the current page, but without scanning through all controls (slow) I can’t see a way of doing that easily.

 

The control caches each of the MethodInfo structures to defer some of the overhead in making the Reflection calls to the ScriptManager methods. I don’t think that Reflection here is going to cause much worry about overhead unless you have a LOT of calls to these methods (I suppose it’s possible if you have lots of resources – think of a control like FreeTextBox for example). Even then the Reflection overhead is probably not worth worrying about.

 

To use this class all calls to ClientScript get replaced with call this class instead. So somewhere during initialization of the control I add:

 

protected override void OnInit(EventArgs e)

{

    this.ClientScriptProxy = ClientScriptProxy.Current;

    base.OnInit(e);

}

 

And then to use it:

 

this.ClientScriptProxy.RegisterClientScriptInclude(this,this.GetType(),

           ControlResources.SCRIPTLIBRARY_SCRIPT_RESOURCE,

           this.ResolveUrl(this.ScriptLocation));

 

Notice the first parameter is the control instance (typically this) just like the ScriptManager call, so there will be a slight change of parameters when changing over from ClientScript code.

 

Once I added this code to my controls the problems with UpdatePanel went away and it started rendering properly again even with the controls hosted inside of the UpdatePanels.


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产精品日日做人人爱| 国产精品亚发布| 国产精品欧美激情在线播放| 欧美性在线观看| 狠狠操狠狠色综合网| 国产一区红桃视频| 黑人欧美xxxx| 热久久视久久精品18亚洲精品| 91久久久久久久久久久| 久久久久久久久91| 4p变态网欧美系列| 午夜精品国产精品大乳美女| 欧美日韩在线视频一区二区| 亚洲美女福利视频网站| 97香蕉久久夜色精品国产| 精品国产自在精品国产浪潮| 亚洲男人天堂久| 成人久久一区二区三区| 久久免费少妇高潮久久精品99| 91在线高清免费观看| 欧美日韩视频免费播放| 国产精品免费小视频| 欧美精品久久久久| 亚洲欧洲自拍偷拍| 欧美国产精品人人做人人爱| 91精品国产综合久久香蕉最新版| 黑人巨大精品欧美一区二区三区| 成人网页在线免费观看| 粉嫩老牛aⅴ一区二区三区| 欧美插天视频在线播放| 国产精品亚洲网站| 美女扒开尿口让男人操亚洲视频网站| 欧美精品videosex性欧美| 欧美视频在线观看 亚洲欧| 国产一区二区在线免费视频| 欧美一区二区色| 国产精品自产拍在线观| 国产精品免费小视频| 国产精品女主播| 岛国av一区二区三区| 欧美激情中文字幕在线| 午夜精品久久久久久久久久久久| 久99久在线视频| 日本高清+成人网在线观看| 国产日韩精品视频| 亚洲国产欧美一区二区三区久久| 91久久精品一区| 成人在线视频网| 欧美日韩美女在线| 欧美黄网免费在线观看| 91精品国产综合久久香蕉最新版| 国产一区二区久久精品| 欧美理论电影网| 亚洲欧美色图片| 懂色av一区二区三区| 中文字幕日韩专区| 韩国美女主播一区| 91久久久精品| 色婷婷亚洲mv天堂mv在影片| 亚洲欧美成人精品| 日韩av影片在线观看| 欧美精品videosex牲欧美| 亚洲美女性视频| 成人黄色av播放免费| 亚洲天堂精品在线| 亚洲人成电影网站色| 成人在线视频网| www.xxxx精品| 国产亚洲一区二区在线| 亚洲另类欧美自拍| 久久久久日韩精品久久久男男| 午夜精品福利视频| 91精品国产自产在线老师啪| 中文字幕精品—区二区| 日韩精品亚洲视频| 国产精品av网站| 97视频免费看| 国产精品视频999| 日韩中文字幕网站| 亚洲一二三在线| 色偷偷噜噜噜亚洲男人| 国产美女精品免费电影| 亚洲a在线播放| 深夜成人在线观看| 国产va免费精品高清在线观看| 国产精品久久久久av| 国产91精品高潮白浆喷水| 国产区精品视频| 国产日本欧美在线观看| 欧美亚洲第一区| 国产成人免费av电影| 日韩欧美在线免费| 夜夜嗨av色综合久久久综合网| 国产精品亚洲一区二区三区| 国产精品久久久久久久久免费看| 国产精品综合不卡av| 日韩电影免费观看中文字幕| 日韩电影在线观看永久视频免费网站| 国产精品91一区| 91精品国产电影| 国产精品日本精品| 日本免费久久高清视频| 精品视频在线导航| 亚洲精品一区久久久久久| 在线观看日韩专区| www日韩中文字幕在线看| 国产精品视频永久免费播放| 日韩在线中文视频| 欧美一级成年大片在线观看| 中文字幕亚洲激情| 国产精品美女999| 亚洲日本aⅴ片在线观看香蕉| 亚洲欧美国产精品| 成人亲热视频网站| 亚洲激情在线观看视频免费| 欧美一级高清免费| 亚洲精品成人久久| 性色av一区二区三区红粉影视| 国产日韩欧美在线观看| 亚洲欧洲日产国产网站| 精品偷拍一区二区三区在线看| 黄色成人av网| 亚洲精品久久在线| 久久久久久久久久国产精品| 久久久中文字幕| 亚洲国产精彩中文乱码av在线播放| 庆余年2免费日韩剧观看大牛| 亚洲乱码一区二区| 成人写真视频福利网| 亚洲国产成人精品女人久久久| 日本久久亚洲电影| 久久91亚洲精品中文字幕奶水| 亚洲欧洲一区二区三区久久| 韩日精品中文字幕| 7777免费精品视频| 91精品久久久久久久久久久| 欧美第一黄色网| 久久久久久午夜| 中文字幕视频在线免费欧美日韩综合在线看| 亚洲国产成人一区| 日韩精品在线视频美女| 欧美亚州一区二区三区| 亚洲一品av免费观看| 国产一区二区三区视频免费| 在线观看日韩专区| 精品成人69xx.xyz| 91精品国产综合久久香蕉| 91精品国产高清久久久久久久久| 亚洲视频一区二区| 久久精品中文字幕电影| 欧美久久精品午夜青青大伊人| 精品视频9999| 91免费在线视频| 欧美日韩亚洲一区二| 色婷婷av一区二区三区久久| 欧美性生活大片免费观看网址| 久久99久久久久久久噜噜| 亚洲人成绝费网站色www| 亚洲第一精品夜夜躁人人爽| 中文字幕久久精品| 日韩av片永久免费网站| 欧美人在线视频| 欧美高跟鞋交xxxxhd| 久久久久久久久亚洲|