Click here to Skip to main content
15,920,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i created a user control.
into user control have image element.
ASP.NET
<img id="imgNews"  src="Images/twitter-256.png"  runat="server" />

and created property:
C#
string srcNews;

        public string SrcNews
        {
            get { return srcNews; }
            set { srcNews = value;
           
            }
        }

already, i use usercontrol in my website .
i want set attribute src from image user control from my web site .
how i can ?
Posted
Comments
ZurdoDev 29-Jun-14 20:47pm    
What's your question? You have a property. Now all you need to do is use it.

Your Page you Should Register Like wise

]]>
]]>

Body Section like wise



<snp:usernews id="userNews" runat="Server" xmlns:snp="#unknown">

<asp:button id="btn1" runat="server" text="Click" xmlns:asp="#unknown">


codeFile have :
C#
protected void Page_Load(object sender, EventArgs e)
      {
          if (Page.IsPostBack)
              userNews.SrcNews = "Chrysanthemum.jpg";
      }


usercontrol modify the Property
C#
public string SrcNews
{
    get { return imgNews.Attributes["src"];}
    set { imgNews.Attributes["src"] = value;}
}


i hope this code will work
 
Share this answer
 
In your source code you should change your SrcNews property like bellow:
C#
public string SrcNews
{
    get { return imgNews.Attributes["src"];}
    set { imgNews.Attributes["src"] = value;}
}
 
Share this answer
 
Hi
i have one clarification.before accessing the property you could create the instance for that user control and try to access that property "SrcNews".

Ex:
you have registered one usercontrol called "Usercontrol1.ascx".
you write the code like wise

Usercontrol1 objUserControl=Page.FindControl("Usercontrol1.ascx");
objUserControl.SrcNews="";


now you may access this property.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900