__doPostback method with colons problem

  • Thread starter Thread starter Steven Livingstone
  • Start date Start date
S

Steven Livingstone

I am running into the "colon in javascript" problem as discussed here
http://www.bdragon.com/entries/000324.shtml.

Basically, i have nested controls and get the error on a line such as :

theform = document._ctl0:frmPage;

I noticed a solution at
http://msdn.microsoft.com/msdnmag/issues/02/10/WebQA/
However, this seems like a heck of an overhead for every page!

Has anyone got any updates on if/when and how this can be fixed without
resorting to these kind of fixes? Seems a fairly fundamental problem to me,
so hopefully it has already been fixed and i'm just missing some upgrade or
hot fix!!

thanks,
Steven
 
FWIW :

I have discovered that the basic problem is that i have the FORM defined
within a usercontrol.
It then turns out that "ucForm" is referenced in the __doPostBack method as
:

theform = document._ctl0:ucForm;

Fails in JavaScript :(

Any fixes?
 
ok - 1 way around it i have found (based on an earlier uri).

Override the render method in the control and replace ":" for control names
with "_".

Works thus far - anyone tried this and run into any probs?

Still is not something i want to put into prod :S
 
Hi JD - I have actually written a framework which uses a core usercontrol to
implement the look and feel any application and all it's (reusable) sub
controls. I tried a whole host of ways, but this is the only way i can see
it working and still be extensible.

This main control hosts the other controls and the page acts as a simple
container which the <form> wrapper in it. So that control itself is never
reused outside its parent page.

In other cases i may well write a full encapsulated "poll control" with the
form element to be just dropped into any asp page. I don't in my case, but
i'd like ASP.Net to support that possibility!

Cheers,
Steven.
 
You might try this. You may have to modify it a bit but I don't think the
overhead is too bad.
(Not my idea, but it works real well) I left some of the old code that I
didn't need in there in case you need it. Hope this helps you.


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;")

'Dim intend As Integer = 6 + start 'html.IndexOf("""", start)
if start <> -1 then

'Dim formID As String = html.Substring(start, intend - start)
'Dim replace As String = formID.Replace(":", "_")
html = html.Replace("document._ctl1:_ctl0", "document._ctl1__ctl0") ' you
may need to change
end if

writer.Write(html)

End Sub
 
Hi Michael -

thanks for your code. In fact it is very simialr to the solution i decided
upon last night and it works great.
I will compare yours to see if there is anything i should add :)

Still a bit of a hit, but hopefully it will be fixed sometime soon.

cheers,
steven
 
John, go to the second Q on that page and click the "Figure 1" link to view
the code listing.
 
Hello Steven,

This happens when asp.net form is included into control in framework 1.1. It seems that this is not welcomed way to build
webforms, but anyway sometimes this can be very useful. This must work on .net 1.0.

The workaround now is to override control's holding <form> method Render, again, it is possible override Render method of
page alltogether.

Thanks.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "Steven Livingstone" <[email protected]>
!References: <#[email protected]> <[email protected]>
<[email protected]> <[email protected]>
!Subject: Re: __doPostback method with colons problem
!Date: Tue, 5 Aug 2003 15:02:16 +0100
!Lines: 56
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <[email protected]>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: 212.20.246.65
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:164973
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!John, go to the second Q on that page and click the "Figure 1" link to view
!the code listing.
!
!!> Steven, I don't see anything about PageParser in that Q&A.
!> --
!> John Saunders
!> Internet Engineer
!> (e-mail address removed)
!>
!> !> > Hi John - unfortunately i pointed to the wrong Q&A!!
!> > The one i meant to point you to was :
!> > http://msdn.microsoft.com/msdnmag/issues/02/11/WebQA/
!> >
!> > As you can see in that case, the PageParser() methods is a heck of an
!> > overhea for every page!
!> >
!> > Cheers,
!> > Steven
!> >
!> > !> > > !> > > > I am running into the "colon in javascript" problem as discussed
!here
!> > > > http://www.bdragon.com/entries/000324.shtml.
!> > > >
!> > > > Basically, i have nested controls and get the error on a line such
!as
!> :
!> > > >
!> > > > theform = document._ctl0:frmPage;
!> > > >
!> > > > I noticed a solution at
!> > > > http://msdn.microsoft.com/msdnmag/issues/02/10/WebQA/
!> > > > However, this seems like a heck of an overhead for every page!
!> > > >
!> > >
!> > > I'm curious, what part of that do you believe is a "lot of overhead"?
!> > > --
!> > > John Saunders
!> > > Internet Engineer
!> > > (e-mail address removed)
!> > >
!> > >
!> > >
!> >
!> >
!>
!>
!
!
!
 
Actually, the workaround we use is to not use Framework 1.1.

The fix would be for Microsoft to fix its bug. It would be just as easy to
ignore the Netscape branch of that "if" statement (with a comment saying,
"our bad: here's the stupid code we would have produced, we'll fix it soon,
don't sue us") as to break our web sites for both Netscape and IE by
treating the form name as an identifier (is it supposed to be an
identifier?).
--
John Saunders
Internet Engineer
(e-mail address removed)

Yan-Hong Huang said:
Hello Steven,

This happens when asp.net form is included into control in framework 1.1.
It seems that this is not welcomed way to build
webforms, but anyway sometimes this can be very useful. This must work on ..net 1.0.

The workaround now is to override control's holding <form> method Render,
again, it is possible override Render method of
page alltogether.

Thanks.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello John,

Yes, I agree with you. In fact, it has been logged into our internal
database. We are working on it and it will be integrated into later version
of Visual Studio.

Thanks.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "John Saunders" <[email protected]>
!References: <#[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
!Subject: Re: __doPostback method with colons problem
!Date: Wed, 6 Aug 2003 12:00:13 -0400
!Lines: 122
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <[email protected]>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: pool-141-149-183-116.bos.east.verizon.net
141.149.183.116
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:165410
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Actually, the workaround we use is to not use Framework 1.1.
!
!The fix would be for Microsoft to fix its bug. It would be just as easy to
!ignore the Netscape branch of that "if" statement (with a comment saying,
!"our bad: here's the stupid code we would have produced, we'll fix it soon,
!don't sue us") as to break our web sites for both Netscape and IE by
!treating the form name as an identifier (is it supposed to be an
!identifier?).
!--
!John Saunders
!Internet Engineer
[email protected]
!
!!> Hello Steven,
!>
!> This happens when asp.net form is included into control in framework 1.1.
!It seems that this is not welcomed way to build
!> webforms, but anyway sometimes this can be very useful. This must work on
!.net 1.0.
!>
!> The workaround now is to override control's holding <form> method Render,
!again, it is possible override Render method of
!> page alltogether.
!>
!> Thanks.
!>
!> Best regards,
!> Yanhong Huang
!> Microsoft Online Partner Support
!>
!> Get Secure! - www.microsoft.com/security
!> This posting is provided "AS IS" with no warranties, and confers no
!rights.
!>
!> --------------------
!> !From: "Steven Livingstone" <[email protected]>
!> !References: <#[email protected]>
!<[email protected]>
!> <[email protected]>
!<[email protected]>
!> !Subject: Re: __doPostback method with colons problem
!> !Date: Tue, 5 Aug 2003 15:02:16 +0100
!> !Lines: 56
!> !X-Priority: 3
!> !X-MSMail-Priority: Normal
!> !X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!> !X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!> !Message-ID: <[email protected]>
!> !Newsgroups: microsoft.public.dotnet.framework.aspnet
!> !NNTP-Posting-Host: 212.20.246.65
!> !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
!> !Xref: cpmsftngxa06.phx.gbl
!microsoft.public.dotnet.framework.aspnet:164973
!> !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!> !
!> !John, go to the second Q on that page and click the "Figure 1" link to
!view
!> !the code listing.
!> !
!> !!> !> Steven, I don't see anything about PageParser in that Q&A.
!> !> --
!> !> John Saunders
!> !> Internet Engineer
!> !> (e-mail address removed)
!> !>
!> !> !> !> > Hi John - unfortunately i pointed to the wrong Q&A!!
!> !> > The one i meant to point you to was :
!> !> > http://msdn.microsoft.com/msdnmag/issues/02/11/WebQA/
!> !> >
!> !> > As you can see in that case, the PageParser() methods is a heck of
an
!> !> > overhea for every page!
!> !> >
!> !> > Cheers,
!> !> > Steven
!> !> >
!> !> > !message
!> !> > > !> !> > > > I am running into the "colon in javascript" problem as discussed
!> !here
!> !> > > > http://www.bdragon.com/entries/000324.shtml.
!> !> > > >
!> !> > > > Basically, i have nested controls and get the error on a line
!such
!> !as
!> !> :
!> !> > > >
!> !> > > > theform = document._ctl0:frmPage;
!> !> > > >
!> !> > > > I noticed a solution at
!> !> > > > http://msdn.microsoft.com/msdnmag/issues/02/10/WebQA/
!> !> > > > However, this seems like a heck of an overhead for every page!
!> !> > > >
!> !> > >
!> !> > > I'm curious, what part of that do you believe is a "lot of
!overhead"?
!> !> > > --
!> !> > > John Saunders
!> !> > > Internet Engineer
!> !> > > (e-mail address removed)
!> !> > >
!> !> > >
!> !> > >
!> !> >
!> !> >
!> !>
!> !>
!> !
!> !
!> !
!>
!>
!
!
!
 
First off I have to say thanks for pointing out those
articles, they helped me figure out the problem. I also
tried what one of the links said, (smaller solution of
name=id), but that still didn't work.

I did however figure out a hack, and that's basically
create the postback yourself.

Remove the autopostback feature on your control, and
instead add the onchange javascript yourself:
frmShippingChargeType.Attributes.Add
("onchange", "doManualPostBack('_ctl1
$frmShippingChargeType','')");

within the .cs file.

then create the two hidden fields that the post back uses:
<input type="hidden" name="__EVENTTARGET"
value="" />
<input type="hidden"
name="__EVENTARGUMENT" value="" />

put these below your <form tag.

Then, and this is the sketchy part is I made a modified
dopostback method:

<script language="javascript">
<!--
function doManualPostBack(eventTarget,
eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase
().indexOf("netscape") > -1) {
theform = document.forms
["_ctl1:frmadminProduct"];
}
else {
theform = document.forms[0];
}
theform.__EVENTTARGET.value =
eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value =
eventArgument;
theform.submit();
}
// -->
</script>

the key line to look at is:
theform = document.forms[0];

this takes the first form on the page and uses it. For
what I'm doing now, that will work, though I don't know
if it will always do the trick for everyone.

However, with these things I've been able to do post
backs and everything else seems to work as normal.
 
David, Thanks for the info.

Doesn't ASP.NET still render its own, incorrect "doPostBack" script?
--
John Saunders
Internet Engineer
(e-mail address removed)

David McCormack said:
First off I have to say thanks for pointing out those
articles, they helped me figure out the problem. I also
tried what one of the links said, (smaller solution of
name=id), but that still didn't work.

I did however figure out a hack, and that's basically
create the postback yourself.

Remove the autopostback feature on your control, and
instead add the onchange javascript yourself:
frmShippingChargeType.Attributes.Add
("onchange", "doManualPostBack('_ctl1
$frmShippingChargeType','')");

within the .cs file.

then create the two hidden fields that the post back uses:
<input type="hidden" name="__EVENTTARGET"
value="" />
<input type="hidden"
name="__EVENTARGUMENT" value="" />

put these below your <form tag.

Then, and this is the sketchy part is I made a modified
dopostback method:

<script language="javascript">
<!--
function doManualPostBack(eventTarget,
eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase
().indexOf("netscape") > -1) {
theform = document.forms
["_ctl1:frmadminProduct"];
}
else {
theform = document.forms[0];
}
theform.__EVENTTARGET.value =
eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value =
eventArgument;
theform.submit();
}
// -->
</script>

the key line to look at is:
theform = document.forms[0];

this takes the first form on the page and uses it. For
what I'm doing now, that will work, though I don't know
if it will always do the trick for everyone.

However, with these things I've been able to do post
backs and everything else seems to work as normal.
-----Original Message-----
Ok, thanks, yes, that's too much overhead.
--
John Saunders
Internet Engineer
(e-mail address removed)

the "Figure 1" link to
view a "lot of
overhead"?

.
 
Back
Top