Calling a c # function from javascript

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

I have a link in my ascx (see code below). The problem is that if you hit enter in firefox it doesn't work, but it works 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 a linkButton as shown above on which I was calling a C # function on Click. But if you added text to the text box and hit "Enter", it should automatically call the "btnSearchNow_Click" function. It works fine in IE but doesn't work in Firefox.

0


source to share


3 answers


The javascript function for clicking the button ...

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

      

Some clearing or additional information could be used in the wording of your question.



If you are looking for a pseudo-representation of behavior inside a textbox check out this post. Send login button when pressing Enter

You will need to generate javascript from the server side as you are using ASCX and the IDs are not the ones you defined.

+1


source


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

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

      



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

0


source


For .Net you can also wrap your page in a panel and use the "DefaultButton" property to select the link.

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

      

0


source







All Articles