Overriding __doPostBack

Discussion in 'ASP .Net' started by Mike Dunn, Jul 9, 2003.

  1. Mike Dunn

    Mike Dunn Guest

    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, Jul 9, 2003
    #1
    1. Advertising

  2. Mike Dunn

    Teemu Keiski Guest

    See this thread on ASP.NET forums

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

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

    ASP.NET Forums Moderator, www.asp.net
    AspAlliance Columnist, www.aspalliance.com

    Email:



    "Mike Dunn" <> wrote in message
    news:026f01c34637$52dcbf10$...
    > 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, Jul 9, 2003
    #2
    1. Advertising

  3. Mike Dunn

    vMike Guest

    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" <> wrote in message
    news:026f01c34637$52dcbf10$...
    > 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, Jul 9, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. paul reed

    Wierd Behavior of __doPostBack

    paul reed, Jul 8, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    582
    Bassel Tabbara [MSFT]
    Jul 8, 2003
  2. Hayato Iriumi

    __doPostBack EventArgument

    Hayato Iriumi, Jul 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    746
    Hayato Iriumi
    Jul 22, 2003
  3. E
    Replies:
    3
    Views:
    4,271
    John Saunders
    Jul 31, 2003
  4. Steven Livingstone

    __doPostback method with colons problem

    Steven Livingstone, Aug 4, 2003, in forum: ASP .Net
    Replies:
    15
    Views:
    777
    John Saunders
    Aug 28, 2003
  5. Ilya Volodin

    __doPostBack problem

    Ilya Volodin, Dec 23, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    544
    Ilya Volodin
    Dec 23, 2003
Loading...

Share This Page