Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Hot to get a value in aspx page from Web.Config file?

Hot to get a value in aspx page from Web.Config file?

Scheduled Pinned Locked Moved ASP.NET
sysadminhelpquestion
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Sam M

    Hi there, I've created a web page and it contains three images. These all images will be changable. So i want to give the path of images in Web.Config file and file name in that particular image src. How i can give that?. Also am using code behind not inline. I wanted to write only in aspx page not in codebehind. Below is my code: Web.Config: <add key="ImagePath" value="http://192.168.0.181/Labeling/Images/"/> and in my aspx page, <img id="ImgHeader" runat="server" src="<%header.gif%>" /> What all the ways available to call WebConfig file values? Please help..!!

    Regards n Thks Sam.M

    N Offline
    N Offline
    N a v a n e e t h
    wrote on last edited by
    #2

    <img id="ImgHeader" runat="server" src='<% ConfigurationManager.AppSettings["ImgHeader"] %>' />

    ?

    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

    S 1 Reply Last reply
    0
    • S Sam M

      Hi there, I've created a web page and it contains three images. These all images will be changable. So i want to give the path of images in Web.Config file and file name in that particular image src. How i can give that?. Also am using code behind not inline. I wanted to write only in aspx page not in codebehind. Below is my code: Web.Config: <add key="ImagePath" value="http://192.168.0.181/Labeling/Images/"/> and in my aspx page, <img id="ImgHeader" runat="server" src="<%header.gif%>" /> What all the ways available to call WebConfig file values? Please help..!!

      Regards n Thks Sam.M

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #3

      string strConfig= System.Configuration.ConfigurationSettings.AppSettings[strKey];

      Best Regards ----------------- Abhijit Jana "Success is Journey it's not a destination"

      modified on Tuesday, May 6, 2008 9:13 AM

      N 1 Reply Last reply
      0
      • A Abhijit Jana

        string strConfig= System.Configuration.ConfigurationSettings.AppSettings[strKey];

        Best Regards ----------------- Abhijit Jana "Success is Journey it's not a destination"

        modified on Tuesday, May 6, 2008 9:13 AM

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #4

        Abhijit Jana wrote:

        string strConfig= System.Configuration.ConfigurationSettings.AppSettings[strKey]; strFilePath = HttpContext.Current.Server.MapPath(strConfig); now read it as XML file

        :confused: What do you mean ? What is the point in reading as XML file for setting a image URL ?

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        S 1 Reply Last reply
        0
        • N N a v a n e e t h

          Abhijit Jana wrote:

          string strConfig= System.Configuration.ConfigurationSettings.AppSettings[strKey]; strFilePath = HttpContext.Current.Server.MapPath(strConfig); now read it as XML file

          :confused: What do you mean ? What is the point in reading as XML file for setting a image URL ?

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

          S Offline
          S Offline
          Sam M
          wrote on last edited by
          #5

          This is not working. I want to write the path only in aspx page and all other code i've written in code behind. Do i need to register any namespace?

          Regards n Thks Sam.M

          D 1 Reply Last reply
          0
          • N N a v a n e e t h

            <img id="ImgHeader" runat="server" src='<% ConfigurationManager.AppSettings["ImgHeader"] %>' />

            ?

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

            S Offline
            S Offline
            Sam M
            wrote on last edited by
            #6

            Sorry. This is not working. It's not retrieving the value from web.Config file. When i right click the image and see the properties it says "Not Available" I want to write the path only in aspx page and all other code i've written in code behind. Do i need to register any namespace?

            Regards n Thks Sam.M

            N 1 Reply Last reply
            0
            • S Sam M

              Sorry. This is not working. It's not retrieving the value from web.Config file. When i right click the image and see the properties it says "Not Available" I want to write the path only in aspx page and all other code i've written in code behind. Do i need to register any namespace?

              Regards n Thks Sam.M

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #7

              Then try

              <img id="ImgHeader" src='<%= ConfigurationManager.AppSettings["ImagePath"] %>' />

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

              S 1 Reply Last reply
              0
              • N N a v a n e e t h

                Then try

                <img id="ImgHeader" src='<%= ConfigurationManager.AppSettings["ImagePath"] %>' />

                All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                S Offline
                S Offline
                Sam M
                wrote on last edited by
                #8

                I tried,but below error is coming: Compiler Error Message: CS1002: ; expected

                Regards n Thks Sam.M

                N 1 Reply Last reply
                0
                • S Sam M

                  I tried,but below error is coming: Compiler Error Message: CS1002: ; expected

                  Regards n Thks Sam.M

                  N Offline
                  N Offline
                  N a v a n e e t h
                  wrote on last edited by
                  #9

                  Yes you need to put ; at the end of statement.

                  <img id="ImgHeader" src='<%= ConfigurationManager.AppSettings["ImagePath"]; %>' />

                  All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                  S 1 Reply Last reply
                  0
                  • N N a v a n e e t h

                    Yes you need to put ; at the end of statement.

                    <img id="ImgHeader" src='<%= ConfigurationManager.AppSettings["ImagePath"]; %>' />

                    All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                    S Offline
                    S Offline
                    Sam M
                    wrote on last edited by
                    #10

                    Thanks. It's working fine.

                    Regards n Thks Sam.M

                    1 Reply Last reply
                    0
                    • S Sam M

                      This is not working. I want to write the path only in aspx page and all other code i've written in code behind. Do i need to register any namespace?

                      Regards n Thks Sam.M

                      D Offline
                      D Offline
                      doWhileSomething
                      wrote on last edited by
                      #11

                      If your images are all going to be assigned via code behind and you have access to the control: imgHeader.ImageUrl = ConfigurationManager.AppSettings["ImgHeader"] + "image.jpg"; or, if your going to use a mixture of code behind and UI, ]]>' /> I think you might be duplicating your assignment of the src value, thus overwritting what is initially set loosing the path.

                      My Personal Site

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups