Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

How do I retrieve a variable in an ASP.Net server control?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JimCinLA - 15 Dec 2007 05:40 GMT
Pardon.  This question seems incredibly dumb but I seem to
be suffering a brain block.  I want an ASP.Net 2.0 image control
to contain a variable for the image file name as shown...

<asp:Image runat="server" ID="myImage" ImageUrl = "<%=myImageFileName
%>"  />

The variable myImageFileName is set in either the Page_Init or
Page_Load
event handler.    The markup appears on a master page which is used
used by .aspx pages in different folders, and at different levels of
indirection with respect to the project root.

Is it that the script is being rendered before Page_Init?
Doesn't sound right.  In fact, if I write

  <td><% = myImageFileName %></td>

the file name shows up on the rendered page as expected.

I believe the previous image tag works if the feature is a client-
side
HTML tag.  That is,

   <img src="<%=myImageFileName %>"  alt="" />

will *probably* produce the desired result.  However, I have used an
active control because the path name in the file name contains the
"~" character, representing the project root which of course
is meaningless in an HTML tag.
Michael Nemtsev [MVP] - 15 Dec 2007 06:44 GMT
Hello JimCinLA,

have u tried to use # sign instead of = ?
Like <img src="<%#myImageFileName %>" alt="" />

or create the function which returs the full path to the image and use this
function in <%=.... %>

---
WBR,
Michael  Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour 

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo

J> Pardon.  This question seems incredibly dumb but I seem to
J> be suffering a brain block.  I want an ASP.Net 2.0 image control
J> to contain a variable for the image file name as shown...
J> <asp:Image runat="server" ID="myImage" ImageUrl = "<%=myImageFileName
J> %>"  />
J>
J> The variable myImageFileName is set in either the Page_Init or
J> Page_Load
J> event handler.    The markup appears on a master page which is used
J> used by .aspx pages in different folders, and at different levels of
J> indirection with respect to the project root.
J> Is it that the script is being rendered before Page_Init? Doesn't
J> sound right.  In fact, if I write
J>
J> <td><% = myImageFileName %></td>
J>
J> the file name shows up on the rendered page as expected.
J>
J> I believe the previous image tag works if the feature is a client-
J> side
J> HTML tag.  That is,
J> <img src="<%=myImageFileName %>"  alt="" />
J>
J> will *probably* produce the desired result.  However, I have used an
J> active control because the path name in the file name contains the
J> "~" character, representing the project root which of course
J> is meaningless in an HTML tag
Stratum - 15 Dec 2007 16:41 GMT
> Hello JimCinLA,
>
[quoted text clipped - 3 lines]
> or create the function which returs the full path to the image and use this
> function in <%=.... %>

Thanks, yes.  But as I explained, it is advantageous to use the
server
control, that is <asp:Image so that the image file's path works for
different levels of indirection.  The image file name is stored in a
database.   The problem is that I can't seem to make the
following work:

   <asp:Image runat="server" ID="myImage"
       ImageUrl = "<%# myImageFileName %>" />

while the code you suggest does work but needs a different
file path depending on which page accesses it.

Jim

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.