开发者

How to change Image inside of CSS of a usercontrol

开发者 https://www.devze.com 2023-01-19 11:09 出处:网络
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..jus

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 con开发者_C百科fusing..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


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消