问题
I have an ImageButton in MasterPage and it's not firing OnClick Event. In pages without a masterpage it works.
http://www.quotehd.com/default.aspx does not have a masterpage and if you enter the word 'funny' in search it works, but if you try to search from http://www.quotehd.com/topics which uses the masterpage it does not fire the code from masterpage.
this is the MasterPage aspx code:
<asp:ImageButton ID="lnkGo1" runat="server" CssClass="searchsubmit"
ImageUrl ="/content/themes/pin/images/search.png" OnClick="lnkGo1_Click"
CausesValidation="False" ViewStateMode="Disabled" EnableViewState="False">
</asp:ImageButton>
C# MasterPage Code:
protected void lnkGo1_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("~/quotes/search/words/" + HttpUtility.HtmlEncode(txtSearch1.Text));
}
the same code works on /default.aspx which does not have a masterpage, but only if you access the homepage with default.aspx
回答1:
I have added this line to MasterPage OnLoad and now it works.
form1.Action = Request.Url.PathAndQuery;
来源:https://stackoverflow.com/questions/15891951/asp-net-4-5-imagebutton-onclick-not-firing-on-masterpage