Why can’t i call ImageButton.ImageUrl??
Default.aspx:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="Test1.jpg" CommandName="Delete" OnCommand="ImageButton_Command" />
</asp:Content>
Default.aspx.cs:
void ImageButton_Command(object sender, CommandEventArgs e)
{
string name = ***ImageButton1.ImageUrl***; //(Error)
}
There is no reason from the code provided for this control not to be recognised; it could be a discrepancy between your
.aspxand.aspx.csfiles (does the former properly relate to the latter?), or it could just be a build problem, have you done a complete clean and rebuild?A solution, regardless of why this is happening for your current situation could be this:
It’s important to do the null check here, since technically this event handler could be called by something other than the button(s) subscribed to raise the event, even though this shouldn’t be the case.