ASP.NET 4.5, ImageButton OnClick not firing on MasterPage

余生颓废 提交于 2020-01-06 02:55:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!