473,398 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Background Image ?

WJ
Is there a way to specify background image for an Aspx page at runtime in c#
? I clicked on the Web form in the IDE (Vs.Net 2003) and it shows
"DOCUMENT", which is not accessible inside code behind c#. On the IDE, I can
set the "background" property to
http://localhost/myWeb/image/myBackGroundImage.gif, however, it would be
nice to do it at runtime also.

Thanks

John
Nov 18 '05 #1
6 2074
One simple way to do this is to declare a string property in the codebehind
Page class, and call it, say, BackgroundImage. Then, put this in your body
tag in the .aspx page:

<body background=<%=BackgroundImage%>>

HTH,
Pete Beech

"WJ" <JW***@Msn2.Com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Is there a way to specify background image for an Aspx page at runtime in c# ? I clicked on the Web form in the IDE (Vs.Net 2003) and it shows
"DOCUMENT", which is not accessible inside code behind c#. On the IDE, I can set the "background" property to
http://localhost/myWeb/image/myBackGroundImage.gif, however, it would be
nice to do it at runtime also.

Thanks

John

Nov 18 '05 #2
WJ
Thanks Pete,

That works very well!

John

"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
One simple way to do this is to declare a string property in the codebehind Page class, and call it, say, BackgroundImage. Then, put this in your body
tag in the .aspx page:

<body background=<%=BackgroundImage%>>

HTH,
Pete Beech

"WJ" <JW***@Msn2.Com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Is there a way to specify background image for an Aspx page at runtime
in c#
? I clicked on the Web form in the IDE (Vs.Net 2003) and it shows
"DOCUMENT", which is not accessible inside code behind c#. On the IDE, I

can
set the "background" property to
http://localhost/myWeb/image/myBackGroundImage.gif, however, it would be
nice to do it at runtime also.

Thanks

John


Nov 18 '05 #3
WJ
One problem with this technique is that now I cannot click on a button to
redirect to another page, it simply blink and remains on the same page,
whicj happens to be the homepage.

John
Nov 18 '05 #4
Hi John,
I've used this technique loads of times, and never had an error like that.
And I can't reproduce the error this time. How are you doing the redirect?
Can you post your .aspx code, and maybe the button handler code? You could
also, as a test, try putting a label and a button on the form, and see if
you can set the labels text in the button handler.

BTW, the code I posted before should be:
<body background="<%=BackgroundImage%>">

Without the quotes round the attribute, the VS.NET design view doesn't work.

Cheers,
Pete Beech

(also, just in case you're using VS.NET 2002, make sure the automatic code
which fixes up the event handler hasn't been removed. That sometimes happens
with that version)

"WJ" <JW***@Msn2.Com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
One problem with this technique is that now I cannot click on a button to
redirect to another page, it simply blink and remains on the same page,
whicj happens to be the homepage.

John

Nov 18 '05 #5
WJ
Pete,

Pete,

Thanks for your reply. Your 1st code works perfectly. I put it in the
background property as "<%=myBackGroundImg%>" at design time, cleared all my
own hardcoded images (background)

Here below is my code in "page1.aspx" and it is this simple, no more no
less.

//****************************************
public class myClass: System.Web.UI.Page
{
private string myPage2="";
public string myBackGroundImg="";

private void Page_Load(object sender,System.EventArgs e)
{
myPage2="http://localhost/myWeb/page2.aspx";
myBackGroundImg="http://localhost/myWeb/image/background.gif";
}

private void buttonPage2_Click(object sender,System.EventArgs e)
{
Response.Redirect(myPage2);
}
}

John

"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi John,
I've used this technique loads of times, and never had an error like that.
And I can't reproduce the error this time. How are you doing the redirect?
Can you post your .aspx code, and maybe the button handler code? You could
also, as a test, try putting a label and a button on the form, and see if
you can set the labels text in the button handler.

BTW, the code I posted before should be:
<body background="<%=BackgroundImage%>">

Without the quotes round the attribute, the VS.NET design view doesn't work.
Cheers,
Pete Beech

(also, just in case you're using VS.NET 2002, make sure the automatic code
which fixes up the event handler hasn't been removed. That sometimes happens with that version)

"WJ" <JW***@Msn2.Com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
One problem with this technique is that now I cannot click on a button to redirect to another page, it simply blink and remains on the same page,
whicj happens to be the homepage.

John


Nov 18 '05 #6
Well, that should work OK, as long as the button Click event is firing OK -
try setting a breakpoint at the Response.Redirect line, or add a label
control to your page1, and set the text to something in the button handler,
to prove that its firing.

If it isn't, open the generated code region and check that the handler is
being set up.

I can't think of anything else, apart from the form tag not being set to
"runat='server' ", or the asp:button tag not being within the form tag.

Pete

PS One unrelated point: its probably better to use relative references, so
rather than having the full URL for the background image and the redirect
URL, you can just use "image/background.gif" and "page2.aspx". This makes
everything more portable.

"WJ" <JW***@Msn2.Com> wrote in message
news:Op****************@TK2MSFTNGP09.phx.gbl...
Pete,

Pete,

Thanks for your reply. Your 1st code works perfectly. I put it in the
background property as "<%=myBackGroundImg%>" at design time, cleared all my own hardcoded images (background)

Here below is my code in "page1.aspx" and it is this simple, no more no
less.

//****************************************
public class myClass: System.Web.UI.Page
{
private string myPage2="";
public string myBackGroundImg="";

private void Page_Load(object sender,System.EventArgs e)
{
myPage2="http://localhost/myWeb/page2.aspx";
myBackGroundImg="http://localhost/myWeb/image/background.gif";
}

private void buttonPage2_Click(object sender,System.EventArgs e)
{
Response.Redirect(myPage2);
}
}

John

"Pete Beech" <pe*********@hotmail.nojunk.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi John,
I've used this technique loads of times, and never had an error like that.
And I can't reproduce the error this time. How are you doing the redirect? Can you post your .aspx code, and maybe the button handler code? You could also, as a test, try putting a label and a button on the form, and see if you can set the labels text in the button handler.

BTW, the code I posted before should be:
<body background="<%=BackgroundImage%>">

Without the quotes round the attribute, the VS.NET design view doesn't

work.

Cheers,
Pete Beech

(also, just in case you're using VS.NET 2002, make sure the automatic code which fixes up the event handler hasn't been removed. That sometimes

happens
with that version)

"WJ" <JW***@Msn2.Com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
One problem with this technique is that now I cannot click on a button

to redirect to another page, it simply blink and remains on the same page, whicj happens to be the homepage.

John



Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Markus Mohr | last post by:
Hi, everyone, I have a special problem: For every monitor resolution in 200 pixel steps from 800 to 1600 pixels I have an image to be shown as centered background-image. Those images all...
4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
2
by: day | last post by:
I'm trying to use a non-scrolling background image within a div (the non-scrolling part is a "nice-to-have" vs a "have to have"). The style for that is: <div style="height=400px;...
4
by: lindsey.crocker | last post by:
I have this links list with background images set on them which changes when they roll over. The <td> is set valign="middle" however as soon as you apply the rollover to the link, the text jumps...
7
by: Nilesh | last post by:
I am using background-image attribute in a CSS file and linking the CSS file to aspx page. But strangly, background-image attribute is not working for relative URL. e.g. If I apply following css...
3
by: Sridhar | last post by:
Hi, I have created a user control which has the html code as follows <TABLE id="ToolBarTable" cellSpacing="0" cellPadding="0" width="100%" border="0"> <tr> <td align="right"...
3
by: KNDesign | last post by:
I've set a background image to repeat-y and at 100% height. It appears fine when I open the window, but when I resize to a smaller height so that I must scroll down to see the rest, the background...
16
by: stevedude | last post by:
CSS newbie again. I have a problem trying to get coffee mug images within anchor tags to center with my link text for a vertical list menu. If I use the horizontal/vertical properties of...
0
by: ton | last post by:
Hi, I have an Image which is dark grey/black, at the top a white line, at the left site a white line as well. At 192 px from the left of the screen I position a DIV with this image as the...
2
by: thephatp | last post by:
I'm having a problem with IE rendering correctly. I'm experimenting with using all div's in my pages now, and I'm not very familiar with the quirks of IE. I have created a sample page, and I'm...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.