get href attrib of anchor element from code behind in asp.net
hi my dear friends :
how can i get href attrib of anchor element from code behind in asp.net? (c#)why the below codes do n't work?
aspx : <a runat="server" id="lightbox" href='<%# GetImageurl() %>'>
<asp:Image ID="imgInrpvEdit" r开发者_如何学Pythonunat="server" ImageUrl="~/Images/Admin/Unknown.png" />
</a>
code behind :
protected string GetImageurl()
{
return "/Images/Admin/Unknown.png";
}
note : my pages base on master & content pages + In those content pages i have multiview & upper Anchor is inside a view in content page...
best regards
You have to remove
runat="server"
and use this syntax
<%= GetImageurl() %>
If you can't remove runat="server" you can do it code-side:
protected void Page_Load(object sender, EventArgs e)
{
lightbox.Attributes.Add("href", GetImageurl());
}
Update
If you want to use your actual syntax I think you have to call DataBind method:
protected void Page_Load(object sender, EventArgs e)
{
lightbox.DataBind();
}
Maybe your tag is wrong?
try <%= GetImageurl() %>
http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-%283c25242c-3c253d2c-3c252c-3c252c-etc%29.aspx
Somewhere in your page load sequence, you want to have:
lightbox.NavigateUrl = GetImageurl());
Also, you don't need to include an asp:Image, just do this right after the above:
lightbox.ImageUrl = "http://somewhere.jpg"
精彩评论