ASP.NET 4.5, ImageButton OnClick not firing on MasterPage
Asked Answered
C

1

1

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

Chongchoo answered 9/4, 2013 at 1:46 Comment(5)
check that your master page is having runat="Server" in it's form tag or not..Snippet
I don't see any problemRoybal
i Tried your code on my machine under master page and it's works fine.Are you using Ajax like update panel etc into your page.Snippet
I don't have an update panel. the page and all controls have runat="server"Chongchoo
please note that I have routed urls and the search works only if I access the page with /default.aspxChongchoo
C
2

I have added this line to MasterPage OnLoad and now it works.

form1.Action = Request.Url.PathAndQuery;
Chongchoo answered 9/4, 2013 at 19:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.