This is some technical/web development stuff… I am just posting it up here in case it can help anyone who comes across it down the road.
I am currently developing web sites in ASP.NET (using C# and code-behind/VS.NET) and have been very pleased with it and the ease with which many things can be done when compared to “before”.
When I upgraded my .NET version from 1.0 to 1.1 I came across some issues that I hadn’t/haven’t seen mentioned anywhere that I could find… so just in case these can help somebody, I am putting some rambing type of descriptions here.
ASP.NET 1.0 -> ASP.NET 1.1 Upgrade Issues (and fixes): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR OR PROBLEM:
Bizarre(?) runtime error —
Parser Error Message: Type ‘System.Web.HttpBrowserCapabilities’ does not inherit from ‘System.Web.Mobile.MobileCapabilities’.
SOLUTION:
Had to uncomment/remove the browsercaps “result” element in web.config file
COMMENTS:
Doesn’t seem to have affected/broken anything else (so far?)
<browserCaps> <!-- result type="System.Web.HttpBrowserCapabilities" / -->
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR OR PROBLEM:
Paging on datagrids no longer worked, though it worked before, (this also might affect “linkbuttons”? I don’t use them..) and/or javascript errors on pages w/datagrid or linkbuttons on them. The source/cause of the problem was a combination of a “template” system whereby my webforms were using a “template” class derived from system.web.ui.page and the javascript “dopostback” code that is generated to post the form to the server… I had run into this issue before with ASP.NET 1.0 when using an “autopostback” dropdownlist which wouldn’t work automatically in Mozilla until I also implemented the solution below…
SOLUTION:
The dopostback javascript “breaks” due to the fact that a control name (like “ctl0:” or “ctl0_”) is added before the server-side form tag (in the templating / inherit from system.web.ui.page system). Here is a sample full html page which illustrates the problem:
------------------------------------------------------------------- <html> <head> <body> <form name="_ctl0:frmPage" method="post" action="list_emails.aspx" id="_ctl0_frmPage"> <input type="hidden" name="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" value="" /> <script language="javascript"> <!-- function __doPostBack(eventTarget, eventArgument) { var theform; if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) { theform = document.forms["_ctl0:frmPage"]; } else { //this is the line causing the problem (in non-netscape browsers at least): theform = document._ctl0:frmPage; } theform.__EVENTTARGET.value = eventTarget.split("$").join(":"); theform.__EVENTARGUMENT.value = eventArgument; theform.submit(); } // --> </script> <br clear="all" /> <table> <tr> <td><span>1</span> <a href="javascript:__doPostBack('_ctl0$dgData$_ctl1$_ctl1','')">2</a> <a href="javascript:__doPostBack('_ctl0$dgData$_ctl1$_ctl2','')">3</a> <a href="javascript:__doPostBack('_ctl0$dgData$_ctl1$_ctl10','')">...</a></td> </tr> </table> </body> </html> -------------------------------------------------------------------
Javascript/dopostback doesn’t like that colon : in “theform = document._ctl0:frmPage;”
My workaround/solution involved setting the webform Name property = to the webform ID property
(e.g. “frmPage.Name = frmPage.ID;”) when the page is initialized.
This will then output a form tag like:
<form name="frmPage" method="post" action="list_emails.aspx" id="frmPage">
Here is some code which hopefully illustrates the general idea/fix:
On the .aspx page you have the form control:
<form runat="server" id="frmPage"...>
…
Then in the .cs (code behind file) file for the page make sure the form control is declared if not already:
protected System.Web.UI.HtmlControls.HtmlForm frmPage;
…
Then you set up a method (I called it “pageInit()” you can call it whatever) like so:
protected void pageInit() { frmPage.Name = frmPage.ID; }…
Then you call this method you’ve just made in an overridden OnInit method for this page
(VS.NET users – this overridden OnInit is added automatically by VS.NET (I believe) –
if you’re NOT using Visual Studio you’ll have to add your own overridden OnInit if it’s not already there
and probably take out the “InitializeComponent” line shown below as well [that’s VS.NET related – for
designer support]):override protected void OnInit(EventArgs e) { pageInit(); InitializeComponent(); base.OnInit(e); }
COMMENTS:
This has to be done in every page using a form (with a datagrid, autopostback or linkbutton-type controls at least..).
It’s definitely a hack/workaround, there’s probably a better solution (like solving this in the template class itself)
– I just haven’t had the time to look into it.. Note that I could have also included a
<form runat=”server”…> tag in the page template itself (so that every page is automatically a form)
but this won’t work for everybody – I needed to have other non ASP.NET/webforms forms (like a search) on pages,
so this solution was not a possibility
How has your .net experince been?
I’m very happy with ASP.NET… It’s so much easier to modularize and re-use code, making it easier for me to get more done in less time. It’s especially valuable since I’m not only in charge of the “programming”, but also everything else (layout, design, images, content management, etc.) on the site as well. With controls like the validators and repeaters and etc. you save so much time in creation and maintenance where you used to have to do tedious little repetitive tasks to add or update these things. Plus I love C# since it’s so much more like Perl or Java than VBscript was (I hated having to use VBScript for ASP!). I’ve found the combination of using ASP.NET (using “code behind” with VS.NET), with a page “templating” system, plus coding the pages to be as XHTML compliant as possible has worked out well.
That’s not to say that it hasn’t taken a little while to get “used” to things with ASP/.NET or that there aren’t some weird problems/”bugs” sort of things that you come across – it’s just so much more of a pleasure to use than other web development technologies I’ve tried or done in the past. ASP.NET debugging with VS.NET has been a disappointment though – needs improvement. No matter how many times I try and follow all of MS’s “tips” on getting debugging to work automatically through VS.NET I just can’t get it to… Though I can (usually) do it by attaching to the process “manually”, it’s usually just not worth the effort.
I also hope that the MONO project (http://go-mono.org/) continues going well because I’d love to be able to use ASP.NET on a Linux system sometime in the future…. (regardless of the purists who hate M$ wrinkling their noses up at such a thought ;).
Interesting Thoughts….
The debugging in .net works pretty well for me. I can use the tracing on asp.net pages and I pull out the heavyweight debugger for my command line apps…
Have you worked much with Nunit or Nant I have been using them a lot lately and they really making testing and building a snap once you get used to them
have you found any use for the dataset yet?? 😉
I’ve come across the Javascript postback problem too, but I can’t get your solution to work. I’ll be honest, I’m not 100% certain how the solution is meant to work – I’ve put the code in the places I think it should go but it makes no difference, any chance of going into it in a little more detail please?
Hi. I have the same JavaScript problem all over my portal. This is so lame on part of Microsoft.
I will have to spend about 3 days fixing this at least.
This might help…
http://support.microsoft.com/default.aspx?scid=kb;en-us;817779
This is a bug in ASP.Net 1.1, and is discussed in the following Microsoft KB article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;818803
It’s good that MS has found/fixed the bug (in the hotfix mentioned in prev. comments)… however, the “colon problem” fix above is still a helpful solution for any developer who hosts remotely where their web host hasn’t applied the hotfix/patch yet (for whatever reasons).
Thanks a lot for this article, and users comments/links – it helped me understand the scripts errors that I was experiencing during a recent migration (1.0->1.1).
I tried to implement the fix in VB.NET, but a strange thing happened – the frmPage.Name property can be set, but it always reverts back to the default (dangerious/problematic) name. It does not complain (readonly fault) – just plain ignores what name I give it. (Perhaps my page architecture is different, or its VB?)
Unfortuntaly, I am unable to obtain the HotFix (don’t ask why).
The solution that I am using is “crude but effective”, and might be interesting for people who have large sites that need converting. I simply do a string replacement on the rendered output (in my case replace “_ctl0:m_frmMain” with “_ctl0_m_frmMain”). I am not proud of this, but it has helped me meet a deadline!
hey,
for your workaround the HtmlForm.Name property is read-only. It does not have an implementation for set { }. What should I do?
Also, Microsoft has not posted how to obtain the fix in their support site. Anyone who knows that please let me know.