DirectMethod using System.Web.UI.Page extension methods

  1. #1

    DirectMethod using System.Web.UI.Page extension methods

    Hi all,

    As i see while ready different threads in the forum, best performance is guaranted when using DirectMethods as Static.

    But this case is not always possible to realize, for example when u need to access non static Page properties from DirectMethod.

    I tried to find a solution by using extentions, so i create a static class witch include some static methods extending the System.Web.UI.Page control.

    Could these extension methods be used as DirectMethods ?

    Need a confirmation of that, because its decisif for my pattern.
    Thanx in advance
    Last edited by mhammami; Feb 17, 2012 at 9:58 AM.
  2. #2
    Hi,

    All the same, static extension method requires a Page instance.

    There is no a Page instance within a static DirectMethod.

    If you need an access to a Page within a DirectMethod, it should be non-static.
  3. #3
    Thanks for the quick reply.

    That's right, extension needs a class instance but must be defined as static.

    Just one more thing, should this DirectMethod succed?

    public static class DirectMethodManager
    {
    [DirectMethod(Namespace = "INTG", ViewStateMode = ViewStateMode.Enabled, ShowMask = true)]
            public static void ShowCardFromGrid(this System.Web.UI.Page Page, string ID, string RecordID, string SwitchFieldValue, bool IsSmall)
    {...}
    }
  4. #4
    Hi,

    No, it won't work.

    1. A DirectMethod must be called client side.

    2. Its parameters must be passed from client side.

    3. No way to get a Page instance within a static DirectMethod. The same with ViewState.


    I'm not sure how you wanted to use the DirectMethod that you defined.
  5. #5
    Hi,

    I have create a custom Page class for all my application, witch include many generic DirectMethods (example: showing cards from GridPanel witch is extended with some extra properties defining the target card url, the target page mode, etc...), the purpose is to have an "elegant" code for the class written in multiple files, and personnaly i like the extension method concept (used all over the solutions).

    The configuration i want to put seems impossible with extension methods, so i switched to "Partial" and "Virtual" classes witch resolve the problem.

    It is not really a problem with coding, it's just an organisation choise.

    Thanks Daniil for ur reply, this post can be marked as closed.
  6. #6
    Ok, thanks for the update.

Similar Threads

  1. Replies: 2
    Last Post: Jan 10, 2012, 12:23 AM
  2. Replies: 4
    Last Post: Feb 01, 2011, 11:54 AM
  3. [CLOSED] Coolite extension methods documentation?
    By daneel in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 06, 2010, 2:09 PM
  4. Page Ajax Bug System.NullReferenceException
    By walle in forum 1.x Help
    Replies: 1
    Last Post: Jun 27, 2010, 4:48 PM
  5. Coolite extension methods documentation?
    By daneel in forum 1.x Help
    Replies: 0
    Last Post: May 05, 2010, 10:32 AM

Tags for this Thread

Posting Permissions