Custom Web Control Problems (should be easy?)

I've created the following

Master Page, Default.aspx using the master page and then a custom control that sits on my default.aspx page.

Custom controls (header.ascx) has a simple <asp:image> and <asp:label>

I'm trying to just have the <asp:Image tag" ImagUrl update from a method in the controls class backing file haers.ascx.cs file.

For the ascx file I have this for my ImageUrl="<%=GetImageUrl() %>" and I've tried with a # also.

In the backing file (cs) I have public string GetImageUrl() that simply returns a string to the path of my graphic I want to display in the image file.

When I run the page it never fires the method and of course nothing works.

If I just us <img src="<%=GetImageUrl() %>" /> All is fine but I can leverage the (~) relative paths like with server controls.

Is there anyone who might be able to help me out with this I simply want to pass this control a URL Param to feed it Icon path information .

Thanks




Answer this question

Custom Web Control Problems (should be easy?)

  • webmixer

    I'm afraid that these forums are not for asp.net questions. If you go over to www.asp.net, I'm sure they will help you.

    Did you put runat="server" in your image control



  • kennylouie

    Ok, I also posted there under server controls.. Yeah I have runat also.

  • fgalarraga

    put code similar to this in your Header.ascx.cs file

    public string ImageUrl
    {
        get {return aspImageControl.ImageUrl;}
        set {aspImageControl.ImageUrl = value;}
    }

    then you will able to give values as this is property of UserControl like this (in target aspx page)


    <uc1:YourUserControl runat=server ImageUrl="~/whateverImageYouWant.png"> ...

     

    hope this helps



  • Custom Web Control Problems (should be easy?)