Click to See Complete Forum and Search --> : Why does .NET leave out style tags?
DDfunbags
Jun 28th, 2004, 03:23 AM
Why does .NET leave out style tags for non-IE browsers?
I made a label and dropdown box in ASP.NET (been coding VB.NET for a while, just branching into ASP.NET now) and I've noticed that ASP.NET leaves out style tags on browsers that are not IE.
Here's an example of code generated by the same page:
IE:
<span id="_ctl0_lblLabel_2" style="width:100px;">Non-Leavers</span>
Mozilla:
<span id="_ctl0_lblLabel_2">Non-Leavers</span>
The same happens with tables borders and various other things
I would manually change the code in the designer but it has this wonderful habit of chaging any style tags I put it to match actual properties.
I don't want to be defining widths in my style sheets otherwise they will become needlessly oversized.
Is there some kind of setting I'm missing to get these tags generated for non-IE browsers?
dj4uk
Jun 28th, 2004, 03:56 AM
I think .NET generally assumes everything but IE is a downlevel browser. I found the following to my web.config file within system.web to allow additional functions to be used in other browsers.
<browserCaps>
<case match="Gecko/[-\d]+">
browser=Netscape
frames=true
tables=true
cookies=true
javascript=true
javaapplets=true
ecmascriptversion=1.5
w3cdomversion=1.0
css1=true
css2=true
xml=true
tagwriter=System.Web.UI.HtmlTextWriter
<case match="rv:1.0[^\.](?'letters'\w*)">
version=6.0
majorversion=6
minorversion=0
<case match="^b" with="${letters}">
beta=true
</case>
</case>
<case match="rv:1(\.\d+)(\.\d)?(?'letters'\w*)">
version=7.0
majorversion=7
minorversion=0
<case match="^b" with="${letters}">
beta=true
</case>
</case>
</case>
<case match="Opera">
browser=Opera
version=${version}
majorversion=${major}
minorversion=${minor}
frames=true
tables=true
cookies=true
javascript=true
ecmascriptversion=1.3
css1=true
css2=true
xml=true
w3cdomversion=1.0
</case>
</browserCaps>
Dunno if that will help you.
DJ
DDfunbags
Jun 28th, 2004, 04:39 AM
Thanks, I'll give that a try.
DDfunbags
Jun 30th, 2004, 03:45 AM
Sorry for delay in replay, been called to different non-.NET projects for a couple of days.
I put that code into my web.config file within the system.web and it didn't change anything. The style tags are still being ignored.
Thanks though.
dj4uk
Jun 30th, 2004, 03:49 AM
Post the server-side code you are using to generate the tags.
DDfunbags
Jun 30th, 2004, 06:18 AM
It's just using the regular Width properties of the text box or label controls eg:
<asp:Label id="Label1" runat="server" Width="150px">Label</asp:Label>
<asp:TextBox id="TextBox1" runat="server" Width="300px"></asp:TextBox>
The HTML generated on IE is:
<span id="_ctl0_Label1" style="width:150px;">Label</span>
<input name="_ctl0:TextBox1" type="text" id="_ctl0_TextBox1" style="width:300px;" />
See how .NET puts a style="width:300px;" for IE for the text box and style="width:150px;" for the label
The code generated for Mozilla is:
<span id="_ctl0_Label1">Label</span>
<input name="_ctl0:TextBox1" type="text" id="_ctl0_TextBox1" />
It completely ignores the Width settings and leaves out the style tag. The same occures on Opera.
The same will happen with borders around ASP.NET Tables. You define a width and a colour and .NET will impliment the styles for IE and not for Mozilla and Opera etc..
I am looking into this <browsercaps> configuration as this seems to be the way to go according to MSDN and a couple of other sites. At the moment it's not working though. If I get it working, I'll post.
dj4uk
Jun 30th, 2004, 06:22 AM
I honestly hadn't noticed that it did that for textboxes!
I would have thought it was more of a browserCaps issue than a bug in the .NET framework.
If you do find a solution I'd like to know!
Cheers
DJ
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.