从JavaScript射击ASP.NET活动 [英] firing ASP.NET Events from javascript

查看:173
本文介绍了从JavaScript射击ASP.NET活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做从JavaScript使用XMLHTT prequest对象一些直线上升异步调用。如果成功,具有一定的返回值,我愿做一个asynchonous回发更新面板上,并运行一些服务器端方法。这是关于我现在怎么实现它:

I'm doing some straight up asynchronous calls from javascript using the XMLHTTPRequest object. On success, with certain return values, I would like to do an asynchonous post back on an update panel and run some server side methods. This is about how I'm implementing it now:

<script language="javascript">
      function AjaxCallback_Success(objAjax) {
        if (objAjax.responseText == "refresh") {
                document.getElementById('<%= btnHidden.ClientID %>').click();
         }
      }
    </script>
    <asp:UpdatePanel ID="upStatus" runat="server">
    <ContentTemplate>
<asp:Button ID="btnHidden" runat="server" style="display: none;" OnClick="SomeMethod" />
    <asp:DropDownList ID="ddlStatus" field="Orders_Status" parent="Orders" runat="server">
    </asp:DropDownList>
    </ContentTemplate>
    </asp:UpdatePanel>

这与工作流程来做。如果在您的订单上工作,有人发票,然后在状态的可用选项下拉实际上改变。因此,一个定时检查,甚至更改,如果有变化,这通常不会发生,更新面板回发,并在下拉列表中被重新绑定到新的数据表的基础上,从Ajax响应各种文本返回值。

This has to do with work flow. If while you are working on an order, someone invoices it, then the options available in the status drop down actually changes. So a timed even checks for changes and if there is a change, which wouldn't normally happen, the update panel posts back and the drop down list gets re-bound to a new data table based on various return values from the ajax response text.

我原来的code实际上比这要复杂得多,但我只是抽象足以让我的概念清晰。有没有更好的,更清洁的方式通过丢弃隐藏式按键,使直javascript调用,这将导致一个更新面板回发asynchonously和运行服务器端的方法来做到这一点?

My original code is actually much more complicated than this, but I've abstracted just enough to make my concept clearer. Is there a better, cleaner way to do this by dropping the hidden button and making a straight javascript call that will cause an update panel to asynchonously postback and run a server side method?

推荐答案

要非常小心的UpdatePanel,如果不正确使用我解释的这里

Be very careful with UpdatePanels, they can be very heavy if not used properly as I explain here.

但JavaScript来提交表单为:

But the JavaScript for submitting a form is:

__doPostBack('eventTarget','eventArguments');

所以在你的榜样,你就会有这样的:

So in your example you'd have something like:

__doPostBack('<%= btnHidden.ClientID %>','');

这篇关于从JavaScript射击ASP.NET活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆