tags:

views:

1755

answers:

3

Hi,

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.

+1  A: 

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. http://stackoverflow.com/questions/201776/submit-login-control-button-when-i-hit-enter#201822

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.

StingyJack
Hi Jack, Its working again fine for IE and not working for firefox. PLease help I want to call this function on pressing "Enter" button. From textbox
MKS
Hello I am not able to run this on Firefox, Please help
MKS
how can I call c# function through javascript
MKS
Have you installed FireBug and looked for errors in the console?
StingyJack
A: 

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.

Geoff
I have already a link button in my code. Then what is the need of above code in my control
MKS
Hi Geoff any idea how to get this solved. I need to call c# function from my javascript function.
MKS
The linkbutton isn't good enough. For firefox to register the Enter key as a submit, you have to have an input type=submit on your page.
Geoff
A: 

For .Net you could also wrap your page in a panel, and use the "DefaultButton" property to pick the linkbutton.

<asp:Panel DefaultButton="btnSearchNow" runat="server"> ... </asp:Panel>
Mxyzptlk