Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 11th, 2004, 10:02 AM
Authorized User
 
Join Date: Jun 2003
Location: , Quebec, Canada.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default Losing style property

In my page, I have a div that look like this.
Code:
<div id="divTest" style="<% = GetStyle %>">
All is well as long a I don't use the design view. But I make a change in design view, my div get like this
Code:
<div id="divTest">
I lose the style tag. Why do I keep losing the style tag each time a make a change in design view? And why it doesn't do it when I use this
Code:
<img src="<% = GetDistributor() %>/images/<% = GetLanguage() %>/LogoMain.gif">
Stéphane
__________________
Stéphane

A programmer is a device that transform coffee in code lines

\"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.\" Rich Cook
  #2 (permalink)  
Old August 11th, 2004, 12:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

VS.NET 2003 has a habit of reformatting your code everytime you switch between views. It does that automatically. The nice thing is in 2005 it's not supposed to do that.

My guess is because you have static text in the image link that it doesn't remove it. Try this:

<div id="divTest" style="<% = GetStyle %>;">

Again, strictly a guess.

Brian
  #3 (permalink)  
Old August 11th, 2004, 12:17 PM
Authorized User
 
Join Date: Jun 2003
Location: , Quebec, Canada.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tryed it with
Code:
<div id="divTest" style="<% = GetStyle %>;">
but I got
Code:
<div id="divTest" style="GetStyle: ">
Well look like I'll have to wait for VS.NET 2005

Stéphane
  #4 (permalink)  
Old August 11th, 2004, 01:22 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Stéphane,

You are missing an important point of ASP.NET programming. You need to get away from the code-embedded-in-html ways of classic ASP. It's particularly applicable to your image. If you need a programmatically modifiable image tag, use the asp:image control and runtime code to change its image url:

    <asp:image id="imgLogo" runat="server" />

Runtime code (perhaps in page_load):

    imgLogo.ImageUrl = String.Format("{0}/images/{1}/LogoMain.gif", GetDistributor(), GetLanguage())

This makes all parts of the code much more readable and follows the proper programming model of web forms.

You can do the same thing with your div tag. However, because there is no div server control in .NET, the control will be an HtmlGenericControl:

    <div id="divTest" runat="server">

Runtime code:

    divTest.Attributes.Item("style") = GetStyle

If you follow these guidelines, you shouldn't experience VS.NET interfering with your markup and you'll have much better luck overall when dealing with web forms.

Peter
-------------------------
Work smarter, not harder
  #5 (permalink)  
Old August 11th, 2004, 01:53 PM
Authorized User
 
Join Date: Jun 2003
Location: , Quebec, Canada.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter

Our product must be white label. We have decide to keep using the old way for the control that are use for the label. We don't want those control to be run at the server because they will use memory for nothing.

Stéphane
  #6 (permalink)  
Old August 11th, 2004, 02:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

<%= GetStyle %> is still run at the server. Peter's way of doing it adds the style attribute with no more processing efforts than <% %> way of doing it.

Brian
  #7 (permalink)  
Old August 11th, 2004, 03:16 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

And not only will GetStyle run on the server, the whole div tag runs at the server.
*Everything* in your page, including whitespace, spaces etc will be seen as a server side control. You may not be able to talk to them directly if you do not define a declaration for them in the Code Behind, but they are server side controls anyway.,

Cheers,

Imar
  #8 (permalink)  
Old August 12th, 2004, 11:04 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

And to harp on the subject...

Improper use of inline <% %> is actually MORE resource intensive then using the predesigned object model and server code methods supported by .NET.
  #9 (permalink)  
Old August 12th, 2004, 11:05 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Stéphane -

What do you mean by "white label"?
  #10 (permalink)  
Old August 12th, 2004, 12:26 PM
Authorized User
 
Join Date: Jun 2003
Location: , Quebec, Canada.
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

White label is use to descrive a program that you develop but is commercialise by a Company X using there name and mayby by your own company.

Stéphane




Similar Threads
Thread Thread Starter Forum Replies Last Post
Style property of datagridview watashi C# 2005 2 January 22nd, 2008 09:58 PM
Losing ODBC connection kornshell SQL Server ASP 0 June 18th, 2007 09:52 AM
Losing variables bluemat XSLT 2 October 16th, 2004 01:59 AM
difference between style.visibility and style.disp Mimi Javascript How-To 6 September 17th, 2003 11:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.