Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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
 
Old October 25th, 2006, 09:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default Change page form style in VB

It is possible to change the style of attributes of an object on a page like this:

object.Style.Add("font-family", "Arial")

This works for divs, spans, tables, text boxes, etc., but I cannot seem to find a way to do this for the overall form (I want to change the background graphic). Neither "me" nor "page" have a style property and a reference to the form by name returns the "type cannot be used in expression" error in the compiler.

Is this not possible?
 
Old October 25th, 2006, 12:05 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You have to explicitly make a reference to the form in code:

Dim Form1 As System.Web.UI.HtmlControls.HtmlForm

You can now do Form1.Style.Add([style])

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 25th, 2006, 12:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Not quite. This appears to create a NEW form by the name of Form1.

Form1.Style.Add("color", "red")

...produces the "object reference not set" error.

I need to reference the page associated with the code behind that is trying to set the style, not a new form.
 
Old October 26th, 2006, 08:02 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ron, I have looked through my code library and can not find where I have done this (to be honest I only have ever had to do it once) but my only other suggestion would be to do something like:

Dim Form1 As System.Web.UI.HtmlControls.HtmlForm = Page.FindControl("Form1")

if you get a cast error, just use CType. hth.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 26th, 2006, 10:21 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey Ron

Just try this, it will work;

Dim form As HtmlForm = CType(Page.FindControl("Form1"), HtmlForm)
form.Style.Add("background-color","Red")


Regards
Mike
 
Old October 26th, 2006, 11:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Great! Thanks!

Know where I can find a list of all the possible style properties that can be used? I believe the last time I tried to use Style.Add, I discovered that the list of properites was not identical to those that could be entered in the style property in HTML. I am, for example, trying to change the tiled graphic on the form, but neither of these seems to work (although background to red, as with Mike's example, works as expected):

form.Style.Add("background", m_strTileGraphic)

form.Style.Add("background-image", m_strTileGraphic)

I'd be happy to know which property I need to do just this, but even better would be a complete list for future reference. I found such a site once, but fogot to add it to my favorites and now I can't seem to find it again.

Thanks, again!
 
Old October 26th, 2006, 11:59 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ron,
   If you MUST do this in code, I am not sure where you would find the list; alternatively since you can reference the Form object itself you can also access its "class" property.

What you could do is either link to an external style sheet or build a style on the page itself so for example

.formMain{
 color: #FF2400;
}

In your codebehind you could do: Form1.Class = "formMain"

hth

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old October 26th, 2006, 12:18 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Unfortunately, I apparently MUST do this in code. This is the same dynamically generated page discussed in our previous thread regarding uploading files. The program used to generate the form tag with the necessary style attributes and this only became an issue because the need to hard-code the file upload object forced me to also hard-code the form tags to contain it (VS doesn't like input tags outside of a form tag). Each form is unique in appearance and external CSSs won't work because the CSS would have to change for each form.

I had figured out how to change the form attributes using script, but that seemed like an even worse solution than using style.add for a variety of reasons. If it's possible to construct a CSS above the HTML inside the ASP page for local reference, as you seem to imply, I'd be happy to do so as the effect would at least be visible in the HTML delivered to the browser. But the only references I've been able to find to CSSs require an external CSS which would not work in this instance.

I was, btw, able to get Mike's code to work for tiled backgrounds:

form.Style.Add("background-image", "url(" & m_strTileGraphic & ")")

The problem wasn't the property referenced, but the strange need to enclose the graphic in the URL() function(?) inside the quotes.

Thanks again!





Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic change of style rajesh_css Javascript 3 October 10th, 2008 04:45 AM
Change C# application Visual Style niting85 .NET Framework 2.0 0 April 30th, 2007 03:27 AM
change style.backgroundColor the reset all others crmpicco Javascript How-To 2 September 29th, 2005 09:52 AM
!resolved! - a change in coding style grimmy PHP How-To 1 June 27th, 2004 10:21 AM





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