如何使用 __doPostBack() [英] How to use __doPostBack()
问题描述
我正在尝试使用 __doPostBack()
在 ASP.NET 中创建异步回发,但我不知道该怎么做.我想使用原生 JavaScript.
I'm trying to create an asyncrhonous postback in ASP.NET using __doPostBack()
, but I have no idea how to do it. I want to use vanilla JavaScript.
像按钮点击这样简单的事情会导致 __doPostBack()
事件触发.我只是想了解该机制的工作原理.
Something simple like a button click can cause the __doPostBack()
event to fire. I'm just trying to learn how the mechanism works.
推荐答案
您可以在 Web 表单中使用名为 btnSave 的按钮尝试此操作,例如:
You can try this in your web form with a button called btnSave for example:
<input type="button" id="btnSave" onclick="javascript:SaveWithParameter('Hello Michael')" value="click me"/>
<script type="text/javascript">
function SaveWithParameter(parameter)
{
__doPostBack('btnSave', parameter)
}
</script>
在你的代码后面添加类似这样的东西来读取值并对其进行操作:
And in your code behind add something like this to read the value and operate upon it:
public void Page_Load(object sender, EventArgs e)
{
string parameter = Request["__EVENTARGUMENT"]; // parameter
// Request["__EVENTTARGET"]; // btnSave
}
尝试一下,让我们知道它是否适合您.
Give that a try and let us know if that worked for you.
这篇关于如何使用 __doPostBack()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!