GetPostBackEventReference - dynamic argument

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default GetPostBackEventReference - dynamic argument

    Hello,

    I'm building a sever control that is essentially a container that holds a
    bunch of DIVs. I want the click event on any of the DIVs to bubble up to the
    container which calls the __doPostback procedure as given by the server-side
    call to ScriptManager.GetPostBackEventReference(Me, sArg). I only want to
    have the __doPostback call on the table level, not on each and every Div
    (there are a lot). So, essentially I would like my call to look like this:

    __doPostback ('My$Control1', e.srcElement.id)

    Unfortunately, GetPostBackEventReference provides the second argument in
    quotes, so it looks like this:

    __doPostback ('My$Control1', 'e.srcElement.id')

    And therefore my return argument is the literal value "e.srcElement.id", not
    the ID of the source element as I would like. Any help here? I could
    hardcode the call like this:

    "__doPostback(" & me.UniqueID & ", e.srcElement.id)"

    but I'm trying to do it the "right" way. Any suggestions?? TIA,

    Monty


    Monty Guest

  2. Similar Questions and Discussions

    1. another url in argument
      Hi guys, I have to use something like this: http://www.mysite.com/script.php?url=http://www.anothersite.com/script.php?another_var=etc but it...
    2. argument is not a valid
      I have installed PHP 5. When I test various php/mysql scripts I`ve written earlier (php 4) I get this kind of warning on every one (Connecting...
    3. argument of webservice
      Hello, I have tried to pass a string parameter to webservice like this : On client side (javascript) : var iCallID ; .... var s s =...
    4. [PHP-DEV] imap_append (fifth argument)
      This seems trivial enough that there's no reason not to fold it into PHP5. I do have a couple questions though: 1) What is the expected format of...
    5. [PHP-DEV] imap_append (fifth argument)
      Hello, I have a question about imap_append function. Why don't you (or php developers) use this patch in new php release? :...
  3. #2

    Default RE: GetPostBackEventReference - dynamic argument

    Hello Monty,

    From your description, you're developing a custom ASP.NET webserver control
    which need to do the following things:

    ** include multiple <div> elements
    ** let the each <div> raise a control postback event when user click on it
    ** pass the client-side <div> ID (which trigger the postback event) into
    the __doPostBack client procedure,

    is this correct?

    Based on my research, when you use
    Page.ClientScript.GetPostBackEventReference method, it will always treat
    the second parameter(argument) as a plain string text and the output script
    statement will wrapper it with a single quote pair( ''). If you want to
    embeded script code, you can do an additional replace on the returned
    script statement. e.g.

    ========================
    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);

    string dopost1 =
    Page.ClientScript.GetPostBackEventReference(this, "{0}");
    string dopost2 =
    Page.ClientScript.GetPostBackEventReference(this, "{0}");


    div1.Attributes["onclick"] = dopost1.Replace("'{0}'",
    "event.srcElement.id");
    div2.Attributes["onclick"] = dopost2.Replace("'{0}'",
    "event.srcElement.id");
    }
    =========================

    Or if you're also attaching an "onclick" handle for each "<div>" tag, you
    can consider directly embeded the div's "ClientID" statically, e.g.

    ===================
    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);

    string dopost1 =
    Page.ClientScript.GetPostBackEventReference(this, div1.ClientID);
    string dopost2 =
    Page.ClientScript.GetPostBackEventReference(this, div2.ClientID);


    div1.Attributes["onclick"] = dopost1;
    div2.Attributes["onclick"] = dopost2;
    }
    =========================

    Hope this helps some.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    [url]http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif[/url]
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    [url]http://msdn.microsoft.com/subscriptions/support/default.aspx[/url].

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.




    Steven Cheng[MSFT] Guest

  4. #3

    Default Re: GetPostBackEventReference - dynamic argument

    Yes, that first method helps. Much better than hard-coding. Thank you!

    "Steven Cheng[MSFT]" <stcheng@online.microsoft.com> wrote in message
    news:wwuUd1TOHHA.2080@TK2MSFTNGHUB02.phx.gbl...
    > Hello Monty,
    >
    > From your description, you're developing a custom ASP.NET webserver
    > control
    > which need to do the following things:
    >
    > ** include multiple <div> elements
    > ** let the each <div> raise a control postback event when user click on it
    > ** pass the client-side <div> ID (which trigger the postback event) into
    > the __doPostBack client procedure,
    >
    > is this correct?
    >
    > Based on my research, when you use
    > Page.ClientScript.GetPostBackEventReference method, it will always treat
    > the second parameter(argument) as a plain string text and the output
    > script
    > statement will wrapper it with a single quote pair( ''). If you want to
    > embeded script code, you can do an additional replace on the returned
    > script statement. e.g.
    >
    > ========================
    > protected override void OnPreRender(EventArgs e)
    > {
    > base.OnPreRender(e);
    >
    > string dopost1 =
    > Page.ClientScript.GetPostBackEventReference(this, "{0}");
    > string dopost2 =
    > Page.ClientScript.GetPostBackEventReference(this, "{0}");
    >
    >
    > div1.Attributes["onclick"] = dopost1.Replace("'{0}'",
    > "event.srcElement.id");
    > div2.Attributes["onclick"] = dopost2.Replace("'{0}'",
    > "event.srcElement.id");
    > }
    > =========================
    >
    > Or if you're also attaching an "onclick" handle for each "<div>" tag, you
    > can consider directly embeded the div's "ClientID" statically, e.g.
    >
    > ===================
    > protected override void OnPreRender(EventArgs e)
    > {
    > base.OnPreRender(e);
    >
    > string dopost1 =
    > Page.ClientScript.GetPostBackEventReference(this, div1.ClientID);
    > string dopost2 =
    > Page.ClientScript.GetPostBackEventReference(this, div2.ClientID);
    >
    >
    > div1.Attributes["onclick"] = dopost1;
    > div2.Attributes["onclick"] = dopost2;
    > }
    > =========================
    >
    > Hope this helps some.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > [url]http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif[/url]
    > ications.
    >
    >
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > [url]http://msdn.microsoft.com/subscriptions/support/default.aspx[/url].
    >
    > ==================================================
    >
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    >
    >
    >

    Monty Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139