我有几个div利用jQuery可拖动的小。这些div放置在中UpdatePanel,并且在dragstop上使用_doPostBack()JavaScript函数。我从页面表单中提取必要的信息。
div
jQuery
UpdatePanel
_doPostBack()
我的问题是,当我调用此函数时,整个页面将重新加载,但我只想重新加载更新面板。
这是一个完整的解决方案
<form id="form1" runat="server"> <asp:LinkButton ID="LinkButton1" runat="server" /> <%-- included to force __doPostBack javascript function to be rendered --%> <input type="button" id="Button45" name="Button45" onclick="javascript:__doPostBack('ButtonA','')" value="clicking this will run ButtonA.Click Event Handler" /><br /><br /> <input type="button" id="Button46" name="Button46" onclick="javascript:__doPostBack('ButtonB','')" value="clicking this will run ButtonB.Click Event Handler" /><br /><br /> <asp:Button runat="server" ID="ButtonA" ClientIDMode="Static" Text="ButtonA" /><br /><br /> <asp:Button runat="server" ID="ButtonB" ClientIDMode="Static" Text="ButtonB" /> </form>
Private Sub ButtonA_Click(sender As Object, e As System.EventArgs) Handles ButtonA.Click Response.Write("You ran the ButtonA click event") End Sub Private Sub ButtonB_Click(sender As Object, e As System.EventArgs) Handles ButtonB.Click Response.Write("You ran the ButtonB click event") End Sub
向客户端呈现了两个输入控件:
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
__EVENTTARGET
__EVENTARGUMENT
__doPostBack函数的呈现方式如下:
function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } }
表单提交/回发时:
javascript:__doPostBack('ButtonB','')
您可以将任何所需的参数传递给 __doPostBack
__doPostBack
然后,您可以分析隐藏的输入值并相应地运行特定代码:
If Request.Form("__EVENTTARGET") = "DoSomethingElse" Then Response.Write("Do Something else") End If
ClientIDMode="Static"
__doPostBack('<%= myclientid.UniqueID %>', '')
__doPostBack('<%= MYBUTTON.UniqueID %>','')