简体   繁体   English

从javascript调用c#函数

[英]Calling c# function from javascript

I want to call ac# function from my javascript function. 我想从我的JavaScript函数中调用ac#函数。

I have a link button in my ascx (please see the code below). 我的ascx中有一个链接按钮(请参见下面的代码)。 The problem is that if you press enter in firefox is not working however it is working fine in internet explorer. 问题是,如果您在Firefox中按Enter键,则无法正常工作,但是在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". 我在上面看到了linkBut​​ton,在Click上我已经调用了c#函数,但是如果您在上面的文本框中显示了一些文本,然后按“ Enter”,它将自动调用函数“ btnSearchNow_Click”。 It is working fine in IE but not working in Firefox. 在IE中运行正常,但在Firefox中却无法运行。

A javascript function to click a button... 点击按钮的JavaScript函数...

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 当我按下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. 您将必须从服务器端生成javascript,因为您使用的是ASCX,并且ID并非您定义的ID。

You need to have a submit type on the page for it to work properly in firefox. 您需要在页面上具有一个提交类型,它才能在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. 编辑: 是具有更多信息的google缓存页面 The original post doesn't seem to be available ATM, but good old google had it. 原始帖子似乎没有自动柜员机可用,但好的旧Google拥有它。

对于.Net,您还可以将页面包装在面板中,然后使用“ DefaultButton”属性选择linkbutton。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM