c# - How do I redirect? -
i have image hyperlink. how access "searchredirect" function redirect server side after image clicked?
<input id="textsearch" runat="server" name="textsearch" type="text" /> <asp:hyperlink id="searchbutton" runat="server"> <img alt="" src="images/searchbutton.png"/> </asp:hyperlink> protected void searchredirect() { response.redirect("/newproject/home/?searchstring=" + textsearch.value; }
rather hyperlink, you'll want use linkbutton , listen click event
<input id="textsearch" runat="server" name="textsearch" type="text" /> <asp:linkbutton id="searchbutton" runat="server" onclick="searchredirect"> <img alt="" src="images/searchbutton.png"/> </asp:linkbutton> protected void searchredirect(sender object, e eventargs) { response.redirect("/newproject/home/?searchstring=" + textsearch.value); }
al kepp suggesting doing way causes page post realize redirect, leading unnecessary page load. javascript version such 1 below avoid first post back:
<input id="textsearch" runat="server" name="textsearch" type="text" /> <a href="#" onclick="window.location='/newproject/home/?searchstring=' + getelementbyid('textsearch').value; return false;"> <img alt="" src="images/searchbutton.png"/> </a>
i didn't test code, don't think have typos.
Comments
Post a Comment