Server variables in ASP.NET Html code

Discussion in 'ASP .Net Web Controls' started by A Traveler, Aug 23, 2004.

  1. A Traveler

    A Traveler Guest

    Given i have some control which has an "ImageURL" property. If this property
    is set, then the HTML code for the web control looks something like:

    <mns:image id=MyImg runat=server ImageURL="images/somepath.jpg"></mns:image>

    Given i have some server variable Session("AppRoot") which declares the full
    path to the root of the application, for example
    Session("AppRoot") = "http://www.someserver.com/myapp/"

    Now is there any way i can put the AppRoot variable directly into the HTML
    control for the mns:image control, rather than having to put code in the .vb
    file to do something like
    MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL

    Could i somehow do SOMEthing like:

    <mns:image id=MyImg runat=server
    ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
    </mns:image>
     
    A Traveler, Aug 23, 2004
    #1
    1. Advertising

  2. A Traveler

    Karl Guest

    There are a number of things I don't understand.

    1-
    If this is your own server control, or you have access to the source, why
    not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in the
    class before the render? This way you don't have to worry about doing it
    either at the page level or the codebehind. If you don't write your own
    that inherits from this one.

    2-
    Does the AppRoot actually belong to the sesssion? it's specific to each
    user?

    3-
    You can simply use ~ to denote the application root, ala:
    ImageUrl="~/images/somepath.jpg"

    4-
    The answer to your question is no..but the solution in #1 will solve her
    right up.

    Karl

    "A Traveler" <> wrote in message
    news:...
    > Given i have some control which has an "ImageURL" property. If this

    property
    > is set, then the HTML code for the web control looks something like:
    >
    > <mns:image id=MyImg runat=server

    ImageURL="images/somepath.jpg"></mns:image>
    >
    > Given i have some server variable Session("AppRoot") which declares the

    full
    > path to the root of the application, for example
    > Session("AppRoot") = "http://www.someserver.com/myapp/"
    >
    > Now is there any way i can put the AppRoot variable directly into the HTML
    > control for the mns:image control, rather than having to put code in the

    ..vb
    > file to do something like
    > MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
    >
    > Could i somehow do SOMEthing like:
    >
    > <mns:image id=MyImg runat=server
    > ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
    > </mns:image>
    >
    >
     
    Karl, Aug 23, 2004
    #2
    1. Advertising

  3. A Traveler

    A Traveler Guest

    Well, i cannot code it into the code for the control, because the control is
    made in a separate library meant ot be generic to NO app in specific.

    I cannot use a Root path ("/" or "~") because the app does not root at the
    root of the site.
    The site's root is www.myserver.com/myapp, not www.myserver.com

    Otherwise then i guess im just stuck having to alter the urls in the .vb
    file then. Thats a little annoying. Itd be nice if you could somehow use
    something like the databinding stuff to put out a server variable into
    ASP.NET html code.

    "Karl" <none> wrote in message news:e$...
    > There are a number of things I don't understand.
    >
    > 1-
    > If this is your own server control, or you have access to the source, why
    > not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in the
    > class before the render? This way you don't have to worry about doing it
    > either at the page level or the codebehind. If you don't write your own
    > that inherits from this one.
    >
    > 2-
    > Does the AppRoot actually belong to the sesssion? it's specific to each
    > user?
    >
    > 3-
    > You can simply use ~ to denote the application root, ala:
    > ImageUrl="~/images/somepath.jpg"
    >
    > 4-
    > The answer to your question is no..but the solution in #1 will solve her
    > right up.
    >
    > Karl
    >
    > "A Traveler" <> wrote in message
    > news:...
    > > Given i have some control which has an "ImageURL" property. If this

    > property
    > > is set, then the HTML code for the web control looks something like:
    > >
    > > <mns:image id=MyImg runat=server

    > ImageURL="images/somepath.jpg"></mns:image>
    > >
    > > Given i have some server variable Session("AppRoot") which declares the

    > full
    > > path to the root of the application, for example
    > > Session("AppRoot") = "http://www.someserver.com/myapp/"
    > >
    > > Now is there any way i can put the AppRoot variable directly into the

    HTML
    > > control for the mns:image control, rather than having to put code in the

    > .vb
    > > file to do something like
    > > MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
    > >
    > > Could i somehow do SOMEthing like:
    > >
    > > <mns:image id=MyImg runat=server
    > > ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
    > > </mns:image>
    > >
    > >

    >
    >
     
    A Traveler, Aug 23, 2004
    #3
  4. A Traveler

    Karl Guest

    ~ uses the virtual app..so it should be ~ should be equal to /myapp

    and you could still make the code generic to no specific app (as it is now
    actually, it's specific to apps at the root level so it isn't very
    generic)...but ~ should do the trick.

    Karl

    "A Traveler" <> wrote in message
    news:...
    > Well, i cannot code it into the code for the control, because the control

    is
    > made in a separate library meant ot be generic to NO app in specific.
    >
    > I cannot use a Root path ("/" or "~") because the app does not root at the
    > root of the site.
    > The site's root is www.myserver.com/myapp, not www.myserver.com
    >
    > Otherwise then i guess im just stuck having to alter the urls in the .vb
    > file then. Thats a little annoying. Itd be nice if you could somehow use
    > something like the databinding stuff to put out a server variable into
    > ASP.NET html code.
    >
    > "Karl" <none> wrote in message

    news:e$...
    > > There are a number of things I don't understand.
    > >
    > > 1-
    > > If this is your own server control, or you have access to the source,

    why
    > > not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in the
    > > class before the render? This way you don't have to worry about doing it
    > > either at the page level or the codebehind. If you don't write your

    own
    > > that inherits from this one.
    > >
    > > 2-
    > > Does the AppRoot actually belong to the sesssion? it's specific to each
    > > user?
    > >
    > > 3-
    > > You can simply use ~ to denote the application root, ala:
    > > ImageUrl="~/images/somepath.jpg"
    > >
    > > 4-
    > > The answer to your question is no..but the solution in #1 will solve her
    > > right up.
    > >
    > > Karl
    > >
    > > "A Traveler" <> wrote in message
    > > news:...
    > > > Given i have some control which has an "ImageURL" property. If this

    > > property
    > > > is set, then the HTML code for the web control looks something like:
    > > >
    > > > <mns:image id=MyImg runat=server

    > > ImageURL="images/somepath.jpg"></mns:image>
    > > >
    > > > Given i have some server variable Session("AppRoot") which declares

    the
    > > full
    > > > path to the root of the application, for example
    > > > Session("AppRoot") = "http://www.someserver.com/myapp/"
    > > >
    > > > Now is there any way i can put the AppRoot variable directly into the

    > HTML
    > > > control for the mns:image control, rather than having to put code in

    the
    > > .vb
    > > > file to do something like
    > > > MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
    > > >
    > > > Could i somehow do SOMEthing like:
    > > >
    > > > <mns:image id=MyImg runat=server
    > > > ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
    > > > </mns:image>
    > > >
    > > >

    > >
    > >

    >
    >
     
    Karl, Aug 23, 2004
    #4
  5. A Traveler

    A Traveler Guest

    Hmm, .. well, i tried using the ~ instead and taking out my code in .vb to
    prepend the approot to the path, but it does not work with the ~.

    Thanks though for the idea.


    "Karl" <none> wrote in message news:...
    > ~ uses the virtual app..so it should be ~ should be equal to /myapp
    >
    > and you could still make the code generic to no specific app (as it is now
    > actually, it's specific to apps at the root level so it isn't very
    > generic)...but ~ should do the trick.
    >
    > Karl
    >
    > "A Traveler" <> wrote in message
    > news:...
    > > Well, i cannot code it into the code for the control, because the

    control
    > is
    > > made in a separate library meant ot be generic to NO app in specific.
    > >
    > > I cannot use a Root path ("/" or "~") because the app does not root at

    the
    > > root of the site.
    > > The site's root is www.myserver.com/myapp, not www.myserver.com
    > >
    > > Otherwise then i guess im just stuck having to alter the urls in the .vb
    > > file then. Thats a little annoying. Itd be nice if you could somehow use
    > > something like the databinding stuff to put out a server variable into
    > > ASP.NET html code.
    > >
    > > "Karl" <none> wrote in message

    > news:e$...
    > > > There are a number of things I don't understand.
    > > >
    > > > 1-
    > > > If this is your own server control, or you have access to the source,

    > why
    > > > not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in

    the
    > > > class before the render? This way you don't have to worry about doing

    it
    > > > either at the page level or the codebehind. If you don't write your

    > own
    > > > that inherits from this one.
    > > >
    > > > 2-
    > > > Does the AppRoot actually belong to the sesssion? it's specific to

    each
    > > > user?
    > > >
    > > > 3-
    > > > You can simply use ~ to denote the application root, ala:
    > > > ImageUrl="~/images/somepath.jpg"
    > > >
    > > > 4-
    > > > The answer to your question is no..but the solution in #1 will solve

    her
    > > > right up.
    > > >
    > > > Karl
    > > >
    > > > "A Traveler" <> wrote in message
    > > > news:...
    > > > > Given i have some control which has an "ImageURL" property. If this
    > > > property
    > > > > is set, then the HTML code for the web control looks something like:
    > > > >
    > > > > <mns:image id=MyImg runat=server
    > > > ImageURL="images/somepath.jpg"></mns:image>
    > > > >
    > > > > Given i have some server variable Session("AppRoot") which declares

    > the
    > > > full
    > > > > path to the root of the application, for example
    > > > > Session("AppRoot") = "http://www.someserver.com/myapp/"
    > > > >
    > > > > Now is there any way i can put the AppRoot variable directly into

    the
    > > HTML
    > > > > control for the mns:image control, rather than having to put code in

    > the
    > > > .vb
    > > > > file to do something like
    > > > > MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
    > > > >
    > > > > Could i somehow do SOMEthing like:
    > > > >
    > > > > <mns:image id=MyImg runat=server
    > > > > ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
    > > > > </mns:image>
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    A Traveler, Aug 23, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. avnrao
    Replies:
    0
    Views:
    3,392
    avnrao
    May 7, 2004
  2. A Traveler

    Server variables in ASP.NET Html code

    A Traveler, Aug 23, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    701
    A Traveler
    Aug 23, 2004
  3. Craig Kenisston

    HTML code warnings in asp.net html code view

    Craig Kenisston, Oct 7, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,171
    Martin Dechev
    Oct 7, 2004
  4. Nick

    ASP/ASP.NET Server Variables

    Nick, May 24, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    441
    clintonG
    May 24, 2006
  5. Replies:
    9
    Views:
    995
Loading...

Share This Page