Home
> Uncategorized > Using OnClientClick with Chrome causes server side submit to fail.
Using OnClientClick with Chrome causes server side submit to fail.
If you embed an asp.net page as an IFrame in a page, where the submit button jumps out of that frame, i.e. in the case of a search form, then you could end up using code like this:
<asp:Button id="btnSearch" runat="server" Text="Search" onclick="btnSearch_Click" OnClientClick="javascript:pageSubmit()" />
<script language="javascript">
function pageSubmit() {
var SearchForm = document.forms[0];
SearchForm.target = ‘_top’;
SearchForm.submit();
}
</script>
However, btnSearch_click doesn’t fire when running under google Chrome …
This is a bit of a hack that I’ve used to get round this:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack && string.IsNullOrEmpty(Request.Form["__EVENTTARGET"]))
{
btnSearch_Click(sender, e);
}
}
No marks for elegance, but it seems to work in Chrome, IE and Firefox.
}
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback