Calling code behind a method from an aspx page
I have an image tag like
<asp:Image ID="ImgProduct" runat="server" ImageUrl='<%# FormatImageUrl("10")%>' />
and in the code I have a method like
protected string FormatImageUrl(string s)
{
return "image"+s;
}
when I rum the code, I expect the HTML image tag with src = "image10" to be displayed.
but nothing happens. Why? any clues?
I am at asp.net. not mvc
on aspx page
<asp:Image ID="ImgProduct" runat="server" ondatabinding="ImgProduct_DataBinding" />
in cs file use this
protected void Page_Load(object sender, EventArgs e)
{
ImgProduct.DataBind();
}
protected void ImgProduct_DataBinding(object sender, EventArgs e)
{
ImgProduct.ImageUrl = "Image pathe + name";
}
.
protected void Page_Load(object sender,EventArgs e)
{
if(!IsPostBack)
{
ImgProduct.ImageUrl = FormatImageUrl("10");
}
}
protected string FormatImageUrl(string s)
{
return "image"+s;
}
I don’t understand what difference does it make for you to bind it to it or write code on the code behind. Saving a few keystrokes? It would be very easy to also observe objects on Codebehind, and not with a data binding expression model