Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turn of Asp.Net Browser Sniffing and altering code

Status
Not open for further replies.

RTomes

Programmer
Apr 19, 2005
357
US
I have a lot of textboxes as follows:
<asp:textbox width="100px" style="LEFT: 720px; position: absolute;"></textbox>

This renders in IE as
<input type="text" style="width:100px;LEFT: 720px;position: absolute;" >

That is not a problem. The problem is in FireFox and Netscape, ASP.Net strips the width like:

<input type="text" style="LEFT: 720px; position: absolute;" >

How do I turn browser sniffing off so ASP.Net does not alter the code going to the browser. An option would be to set ASP.net so it treats all browsers as IE.
FF and NS both understand the css width for textboxes.

I know how to manually change the code and use css. The problem is there are so many textboxes in this project that I need to drag them around in design mode so handing typing them in is not an option.
 
You could try changing the ClientTarget for the page to a downlevel browser and see if that makes a difference (it basically renders the page with HTML 3.2 capabilities i.e. no CSS support). I'm not sure what the outcome would be but it may give you some ideas!

The real problem that you have is that FireFox and Netscape are rendering the HTML as it should be rendered and IE is not (it just so happens that Microsoft promote their own style of rendering HTML, which doesn't conform to the correct standards, when they add attributes to asp.net controls). The only way around it is to use css (which you have already identified) but as you have found out that is not so easy if you are using an editor in "Design View".

Ideally, you wouldn't use any form of absolute positioning for any web page so you should also consider using FlowLayout on your pages (although this is a seperate issue and doesn't affect your "width" problem).

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
I never use the absolute method unless I need to, in this case it is becasue the form elements have to be placed in certain locations to match designated areas on an underlying background image.

I tried changing the ClientTarget and it removed all the style tags without an option to undo. That was what I would think would work to. Luckely, I only had a few textboxes on this form it was not one of the large ones.
 
why not use a common CssClass???

Known is handfull, Unknown is worldfull
 
The width, height, left and top are all different for all 100 controls on the pages, so that won't work well.

I did find a work around for anyone faced with the same issue.
The width and height attributes on <asp:textbox
are server attributes and not client side attributes,
so you need to convert them to css so it renders correctly on other browsers.


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
For Each ctl As Object In Me.Controls
If TypeOf ctl Is TextBox Then
Dim obj As TextBox = ctl
If Not obj.Width.Value = 0 Then obj.Style.Item("width") = obj.Width.Value
If Not obj.Height.Value = 0 Then obj.Style.Item("height") = obj.Height.Value
End If
Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top