问题描述
我有几个小的 DIV
■哪些利用的jQuery
拖动。这些 DIV
,则放置在的UpdatePanel
,并在dragstop我使用 _doPostBack()
JavaScript函数。其中i提取网页形式的必要信息。
I have several small div
s which utilizing jQuery
draggable. These div
s are placed in an UpdatePanel
, and on dragstop I use the _doPostBack()
JavaScript function. where i extract necessary information from the pages form.
我的问题是,当我调用该函数的整个页面重新加载,但我只想重新加载更新面板。
My problem is that when i call this function the whole page is re-loaded but i only want the update panel to be re-loaded.
推荐答案
这里是一个完整的解决方案
<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>
页的code-背后类的整个目录
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
- 包含该LinkButton的,以确保__doPostBack javascript函数呈现给客户端。简单地具有按钮控件不会导致要呈现这个__doPostBack功能。此功能将凭借上具有最ASP.NET页面各种控件的呈现,所以一般不需要空链接按钮
两个输入控件呈现到客户端:
Two input controls are rendered to the client:
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
-
__ EVENTTARGET
接收__doPostBack的参数1 -
__ EVENTARGUMENT
接收__doPostBack的参数2 __EVENTTARGET
receives argument 1 of __doPostBack__EVENTARGUMENT
receives argument 2 of __doPostBack
该__doPostBack函数呈现出这样的:
The __doPostBack function is rendered out like this:
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
- 正如你可以看到,它的值分配给隐藏的输入。
- 如果您提供的服务器控制按钮的的UniqueID按钮单击处理程序要运行(
的javascript:__ doPostBack('ButtonB','')
,那么该按钮时,处理程序将会运行。 - If you provided the UniqueID of the Server-Control Button whose button-click-handler you want to run (
javascript:__doPostBack('ButtonB','')
, then the button click handler for that button will be run.
当表单提交/回传时:
您可以通过任何你想作为参数传递给 __ doPostBack
You can pass whatever you want as arguments to __doPostBack
您可以分析隐藏的输入值,并相应地运行特定的code:
You can then analyze the hidden input values and run specific code accordingly:
If Request.Form("__EVENTTARGET") = "DoSomethingElse" Then
Response.Write("Do Something else")
End If
其他注意事项
- 如果我不知道我想要运行的单击处理控件的ID是什么?
- 如果这是不能接受的设置
的ClientIDMode =静态
,那么你可以做这样的事情:__ doPostBack('&LT;%= myclientid.UniqueID%GT;','')
。 - 或者
__ doPostBack('&LT;%= MYBUTTON.UniqueID%GT;','')
- 这将注入控制的唯一ID到JavaScript中,你应该希望它
- What if I don't know the ID of the control whose click handler I want to run?
- If it is not acceptable to set
ClientIDMode="Static"
, then you can do something like this:__doPostBack('<%= myclientid.UniqueID %>', '')
. - Or:
__doPostBack('<%= MYBUTTON.UniqueID %>','')
- This will inject the unique id of the control into the javascript, should you wish it
这篇关于ASP.NET回发使用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- If it is not acceptable to set
Other Notes
- 如果这是不能接受的设置