Overriding __doPostBack

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

  1. #1

    Default Overriding __doPostBack

    I would like to change the name of the _doPostBack
    function emmitted by the ASP.NET framework to prefix it
    with an ordinal number i.e. the page should show
    <script language="javascript">
    <!--
    function _369__doPostBack(eventTarget,
    eventArgument) {
    var theform =
    document.frmRetailTenantGadget;
    theform.__EVENTTARGET.value = eventTarget;
    theform.__EVENTARGUMENT.value =
    eventArgument;
    theform.submit();
    }
    // -->

    </script>
    The reason for this is I am working on a portal server and
    the output form multiple aspx pages ends up in the same
    HTML page. Multiple declarations of __doPostBack cause a
    problem in the page. I have found one way to do this is to
    override the page render event thus

    protected override void Render
    (HtmlTextWriter writer)
    {
    StringBuilder stringBuilder = new
    StringBuilder();
    StringWriter stringWriter = new
    StringWriter(stringBuilder);
    HtmlTextWriter htmlWriter = new
    HtmlTextWriter(stringWriter);

    base.Render(htmlWriter);

    string html =
    stringBuilder.ToString();

    // Prepend postback scripts with
    gadget ids
    html = html.Replace
    ("__doPostBack", "_" + GadgetId + "__doPostBack");

    writer.Write(html);
    }

    This works but I believe it could cause a problem with
    performance as the find replace is an expensive operation.

    Does anyone know a better (faster? more elegant?) way of
    doing this

    Regards

    Mike


    Mike Dunn Guest

  2. Similar Questions and Discussions

    1. __doPostBack generates JavaScript errors in UserControl encapsulating form
      I have a form shared by several aspx pages. It's the only form appearing on the pages, so I though I would encapsulate the form in a User Control...
    2. __doPostback method with colons problem
      I am running into the "colon in javascript" problem as discussed here http://www.bdragon.com/entries/000324.shtml. Basically, i have nested...
    3. __doPostBack code block not being generated by asp.net page
      I have 2 aspx pages... neither of which do anything out of the ordinary. One of the pages automatically generates this block of code when viewed...
    4. __doPostBack EventArgument
      Hello, guys. I have this javascript to invoke serverside event that is attached to a hidden Button. ...
    5. Wierd Behavior of __doPostBack
      Hello, I am having some weird behavior between two machines...one which is running the 1.1 framework and one which is running 1.0. After opening...
  3. #2

    Default Re: Overriding __doPostBack

    See this thread on ASP.NET forums

    Modifying postback script:
    [url]http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=62695[/url]

    --
    Teemu Keiski
    MCP, Designer/Developer
    Mansoft tietotekniikka Oy
    [url]http://www.mansoft.fi[/url]

    ASP.NET Forums Moderator, [url]www.asp.net[/url]
    AspAlliance Columnist, [url]www.aspalliance.com[/url]

    Email:
    [email]joteke@aspalliance.com[/email]


    "Mike Dunn" <nospammike.dunn@britishland.com> wrote in message
    news:026f01c34637$52dcbf10$a101280a@phx.gbl...
    > I would like to change the name of the _doPostBack
    > function emmitted by the ASP.NET framework to prefix it
    > with an ordinal number i.e. the page should show
    > <script language="javascript">
    > <!--
    > function _369__doPostBack(eventTarget,
    > eventArgument) {
    > var theform =
    > document.frmRetailTenantGadget;
    > theform.__EVENTTARGET.value = eventTarget;
    > theform.__EVENTARGUMENT.value =
    > eventArgument;
    > theform.submit();
    > }
    > // -->
    >
    > </script>
    > The reason for this is I am working on a portal server and
    > the output form multiple aspx pages ends up in the same
    > HTML page. Multiple declarations of __doPostBack cause a
    > problem in the page. I have found one way to do this is to
    > override the page render event thus
    >
    > protected override void Render
    > (HtmlTextWriter writer)
    > {
    > StringBuilder stringBuilder = new
    > StringBuilder();
    > StringWriter stringWriter = new
    > StringWriter(stringBuilder);
    > HtmlTextWriter htmlWriter = new
    > HtmlTextWriter(stringWriter);
    >
    > base.Render(htmlWriter);
    >
    > string html =
    > stringBuilder.ToString();
    >
    > // Prepend postback scripts with
    > gadget ids
    > html = html.Replace
    > ("__doPostBack", "_" + GadgetId + "__doPostBack");
    >
    > writer.Write(html);
    > }
    >
    > This works but I believe it could cause a problem with
    > performance as the find replace is an expensive operation.
    >
    > Does anyone know a better (faster? more elegant?) way of
    > doing this
    >
    > Regards
    >
    > Mike
    >
    >

    Teemu Keiski Guest

  4. #3

    Default Re: Overriding __doPostBack

    Another possible solution (not mine) but it works. I don't know how much
    this slows things down, but it works well for replacing items in the output.
    I use this to fix the Netscape bug in 1.1, but you could use it for other
    things.

    Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

    Dim _stringBuilder As StringBuilder = New StringBuilder()
    Dim _stringWriter As StringWriter = New StringWriter(_stringBuilder)
    Dim _htmlWriter As HtmlTextWriter = New HtmlTextWriter(_stringWriter)
    MyBase.Render(_htmlWriter)
    Dim html As String = _stringBuilder.ToString()
    Dim start As Integer = html.IndexOf("document._ctl1:_ctl0;")
    html = html.Replace("document._ctl1:_ctl0", "document._ctl1__ctl0")
    end if
    writer.Write(html)

    End Sub

    "Mike Dunn" <nospammike.dunn@britishland.com> wrote in message
    news:026f01c34637$52dcbf10$a101280a@phx.gbl...
    > I would like to change the name of the _doPostBack
    > function emmitted by the ASP.NET framework to prefix it
    > with an ordinal number i.e. the page should show
    > <script language="javascript">
    > <!--
    > function _369__doPostBack(eventTarget,
    > eventArgument) {
    > var theform =
    > document.frmRetailTenantGadget;
    > theform.__EVENTTARGET.value = eventTarget;
    > theform.__EVENTARGUMENT.value =
    > eventArgument;
    > theform.submit();
    > }
    > // -->
    >
    > </script>
    > The reason for this is I am working on a portal server and
    > the output form multiple aspx pages ends up in the same
    > HTML page. Multiple declarations of __doPostBack cause a
    > problem in the page. I have found one way to do this is to
    > override the page render event thus
    >
    > protected override void Render
    > (HtmlTextWriter writer)
    > {
    > StringBuilder stringBuilder = new
    > StringBuilder();
    > StringWriter stringWriter = new
    > StringWriter(stringBuilder);
    > HtmlTextWriter htmlWriter = new
    > HtmlTextWriter(stringWriter);
    >
    > base.Render(htmlWriter);
    >
    > string html =
    > stringBuilder.ToString();
    >
    > // Prepend postback scripts with
    > gadget ids
    > html = html.Replace
    > ("__doPostBack", "_" + GadgetId + "__doPostBack");
    >
    > writer.Write(html);
    > }
    >
    > This works but I believe it could cause a problem with
    > performance as the find replace is an expensive operation.
    >
    > Does anyone know a better (faster? more elegant?) way of
    > doing this
    >
    > Regards
    >
    > Mike
    >
    >

    vMike 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