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.

        }

Advertisement
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: