Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call code behind method from aspx page

Tags:

c#

asp.net

i have an image tag like

<asp:Image ID="ImgProduct" runat="server"    ImageUrl='<%# FormatImageUrl("10")%>' /> 

and in code behind i have a method like

protected string FormatImageUrl(string s)
{
return "image"+s;
}

when i rum the code i am expecting that an HTML image tag with src="image10" will render.

but nothing happens why? any clues?

i am in asp.net . not mvc

like image 642
Kuttan Sujith Avatar asked May 21 '11 03:05

Kuttan Sujith


People also ask

How can I see the code-behind ASPX?

Right-click the . aspx page, and then click View Code. The code-behind file opens in the editor.


1 Answers

the <%# .. %> is applied only during data binding. One solution is to manually call DataBind()

Try

protected void Page_Load(object sender, EventArgs e)
{
        ImgProduct.DataBind();
}
like image 141
Bala R Avatar answered Sep 21 '22 03:09

Bala R