Forum Moderators: open

Message Too Old, No Replies

variables in asp net? what the heck

Values and creating web controls

         

makeit

2:24 am on Feb 3, 2004 (gmt 0)

10+ Year Member



why is it that this does not work

<script runat="server">

Sub Page_Load (Sender as Object, E as EventArgs)


dim rootPath as String
dim Backgrd as String

rootPath = "C:\Inetpub\wwwroot\"

FileName.ImageUrl= rootPath &("noe.jpg")
Backgrd= rootPath &("bakladyynew.jpg")

end sub

</script>
<html>
<head>
</head>
<body background="Backgrd" topmargin="0">
<form runat="server">
<asp:Image id="Filename" runat="server"></asp:Image>
</form>
</body>
</html>

the Jpg image"neo.jpg appears. value got through

->FileName.ImageUrl= .

but the ->Backgrd= does not seem to work! I cant pass the values from the server side to the html side
why? If creating my own web controls will make this whole thing easier can someone tell me how to do that? thanks.

I know for text its lbmessage.text
images is image.ImageUrl

but If I claim a variable like ->Backgrd how do I pass that value to the html side.

hope Im clear enough.

duckhunter

3:04 am on Feb 3, 2004 (gmt 0)

10+ Year Member



makeit,
The Image Url comes through because the Image Tag is part of the ASP FORM (<asp:Image), however, the BODY Tag is part of the HTML.

You could try using a Panel control and set it's background property.

f00sion

8:31 pm on Feb 3, 2004 (gmt 0)

10+ Year Member



i am still learning .net but wouldn't this be acceptable?:
<body background="<%=Backgrd%>" topmargin="0">

or are inline expressions out of style now?

duckhunter

4:27 pm on Feb 7, 2004 (gmt 0)

10+ Year Member



Yes, looks like that works. Dim a Public string variable in the code behind .vb page. Then on the Page_Load Event, set it to something.

On the HTML of the ASPX Page. As you coded.
<body bgcolor="<%=BackGrd%>">

then on the .vb codebehind.......

Public BackGrd As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

BackGrd = "green"

End Sub

You will need to compile the project for the .vb code to run.

makeit

8:08 pm on Feb 7, 2004 (gmt 0)

10+ Year Member



Millions of thanks Duckhunter I have been looking for a solution all over the net for the pass 2 weeks. Could not find nothing. I needed to generate background images for my site I did what you said and it work( I only changed

BackGrd = "C:\Inetpub\wwwroot\bakImage.jpg"

server side and

<body background="<%=BackGrd%>">

html side )

I cant beleive it. It's the first time that I participate in a forum and this is realy a great way
to find solutions to coding problems.

I guess I have to learn more about asp.net thanks to all of ya!