Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #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
Reply With Quote
  #7 (permalink)  
Old August 11th, 2004, 03:16 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 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
Reply With Quote
  #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.
Reply With Quote
  #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"?
Reply With Quote
  #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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:16 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.