Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
147 views
in Technique[技术] by (71.8m points)

c# - 如何使用__doPostBack()(How to use __doPostBack())

I'm trying to create an asyncrhonous postback in ASP.NET using __doPostBack() , but I have no idea how to do it.(我正在尝试使用__doPostBack()在ASP.NET中创建异步回发,但我不知道如何做到这一点。)

I want to use vanilla JavaScript.(我想使用vanilla JavaScript。) Something simple like a button click can cause the __doPostBack() event to fire.(像按钮单击这样简单的东西会导致__doPostBack()事件触发。) I'm just trying to learn how the mechanism works.(我只是想了解这种机制是如何运作的。)   ask by Michael Kerute translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can try this in your web form with a button called btnSave for example:(您可以使用名为btnSave的按钮在Web表单中尝试此操作,例如:)

<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.(尝试一下,让我们知道这是否适合您。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...