How to change Image inside of CSS of a usercontrol


Tags: c#,asp.net,css

Problem :

there's a label control on my master page..if its value is "Value1" ,I want this CSS Sprite to display on my webform..if the Value is "Value2"..the CSS sprite should use some different image..just the image needs to be changed ..nothing else in that Sprite..

I found out that I can use "FindControl" method to find out what value that Label Control of Master Page's currently got..

Now how do I change that image on the banner ?? How do I go about it ? Also that CSS Sprite now is a user control named "myBanner.ascx"(earlier was an aspx file)..Now do I need to make 2 diff usercontrols or I can implement some logic in one usercontrol itself ?

Should I make 2 copies of this "myBanner.ascx" with JUST the "image name" changed in its CSS ???

Hope its not confusing..Actually I am lost :/

What I want is ONE banner which has been made using CSS Sprite ..Now if the "Label Control's "value in the master page is "Value1" then the image to be used on that banner is "IMAGE1" else if "Label Control's" value is "Value2" then "IMAGE2" should be used in that sprite..

How do I go about it ? Need just ideas..thnx



Solution :

hmm maybe i'm not understanding this correctly but why don't you make the usercontrol finds the master's label (findcontrol); check the values; and then display the correct image.

the way to display the image you can either have a local variable (in the usercontrol) where you then just drop it in like <%=ImagePath%> and have the check in the pageload

or you can have a method which checks the label like:

<div id="banner" style="background-image:url(<%=GetImagePath()%>);"></div>

backend

protected string GetImagePath() {
 string s = ((Label)this.Page.Master.FindControl("label1")).Text;
 //if ... etc
}

I hope this is what you are looking for otherwise let me know so I can modify my answer

good luck!


    CSS Howto..

    How to keep text in textarea remain at the top?

    CSS how to center ::after pseudo elem

    How to have a backgroud image 100% width / height inside a
  • ?
  • How to change color and background of whole web site

    How to make image stretch to a specific paragraph?

    How to create an enumerated tabular environment in HTML/CSS?

    How to remove CSS triangles?

    How to make this Header/Content/Footer/Menu layout using CSS?

    How to add non-literal into a variable like jQuery?

    How to create DropDown MenuBar using CSS

    In firefox, how to change color of text in a treecell using javascript

    How can I change the colour of a line that starts with specific characters in javascript/css?

    How to Fix Collapsing Top and Bottom Margins?

    Ideas with how to draw a specific large amount of circles on a page using a loop

    How to position an image sprite at the bottom of an element of unknown height

    How to fill the anchor element's height to 100% in html?

    How do you avoid class name collisions? [closed]

    How to make a 3d button

    How to have a multiline CSS horizontal scroll?

    Compass delimited list separator - how to set to – [duplicate]

    How to put a space between the hover effect in this situation css html php?

    How to add background video stop button

    How should I add some space between the text and the border using CSS

    css div and span display differently in browsers. How to unify?

    How can I explain to a programmer that CSS positioning has many benefits over table based layouts?

    How to create a function in which a box moves in accordance with 2 user inputs (direction and # of pixels to move)

    How to setup counters for target-counters

    How can I set the System.Web.Optimization bundler to correctly transform ISO unicode

    How to show divs inline. css html

    How to add decoration to link in CSS?