Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Overriding __doPostBack

Reply
Thread Tools

Overriding __doPostBack

 
 
Mike Dunn
Guest
Posts: n/a
 
      07-09-2003
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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      07-09-2003
See this thread on ASP.NET forums

Modifying postback script:
http://www.asp.net/Forums/ShowPost.a...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:
http://www.velocityreviews.com/forums/(E-Mail Removed)


"Mike Dunn" <(E-Mail Removed)> wrote in message
news:026f01c34637$52dcbf10$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
vMike
Guest
Posts: n/a
 
      07-09-2003
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" <(E-Mail Removed)> wrote in message
news:026f01c34637$52dcbf10$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
__doPostBack problem Ilya Volodin ASP .Net 0 12-23-2003 09:38 PM
__doPostback method with colons problem Steven Livingstone ASP .Net 15 08-28-2003 12:57 AM
__doPostBack code block not being generated by asp.net page E ASP .Net 3 07-31-2003 10:43 AM
__doPostBack EventArgument Hayato Iriumi ASP .Net 0 07-22-2003 04:36 AM
Wierd Behavior of __doPostBack paul reed ASP .Net 1 07-08-2003 04:26 PM



Advertisments