Manoj Singh
Manoj Singh

Reputation: 7707

Calling c# function from javascript

I want to call a c# function from my javascript function.

I have a link button in my ascx (please see the code below). The problem is that if you press enter in firefox is not working however it is working fine in internet explorer.

<li class="clearfix border_top">
<label for="title" class="first_column bold">Search For</label>
<div class="contactUs_details">
<input type="text" id="advanced_txtBox1" name="advanced_txtBox1" class="searchbox" runat="server" style="width:300px;" />&nbsp;&nbsp;&nbsp;&nbsp;
<asp:CheckBox ID="chkSearchBDJ" runat="server" Text="Search BDJ" CssClass="checkboxlistnoborder" />
</div>
</li>

<div class="img_SearchNow">
<asp:LinkButton ID="btnSearchNow" CausesValidation="true" runat="server" OnClick="btnSearchNow_Click"></asp:LinkButton>
</div>

I have linkButton see above on which I have called on c# function on Click, But if you pree some text in above textbox and press "Enter" it should automatically call function "btnSearchNow_Click". It is working fine in IE but not working in Firefox.

Upvotes: 0

Views: 6664

Answers (2)

Geoff
Geoff

Reputation: 9340

You need to have a submit type on the page for it to work properly in firefox.

<input id="mysubmit" runat="server" type="submit" onclick="return false;" style="display: none;" />

Edit: Here's a google cached page that has more information. The original post doesn't seem to be available ATM, but good old google had it.

Upvotes: 1

StingyJack
StingyJack

Reputation: 19489

A javascript function to click a button...

function clickMyButton() {
 var ele = document.getElementById('btnSearchNow');
 if ((ele !== null) && (ele != 'undefined')) {
   ele.click();
 }
}

The wording of your question could use some cleaning up, or some additional information.

If you are looking for pseudo-submit behavior from inside a text box, take a look at this post. Submit Login control button when I hit Enter

You will have to generate the javascript from the server side, since you are using an ASCX and the ID's are not the ones you defined.

Upvotes: 1

Related Questions