asp.net-页面重新加载我的遗嘱 [英] asp.net - page reloaded aginst my will

查看:107
本文介绍了asp.net-页面重新加载我的遗嘱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.
我有一个带有几个按钮的页面.我需要一个按钮来提交表单,而其他按钮来执行页面上的任务,而无需从服务器上重新加载它.出于某种原因,每次按任意按钮都会重新加载页面(输入Page_Load()).
关于我在做什么错的任何想法吗?

谢谢

Hi.
I have a page with several buttons. I need one of the buttons to submit the form and the others to perform tasks on the page without reloading it from the server. For some reason, each time a press any button the page is reloaded (enters Page_Load()).
Any ideas on what I''m doing wrong?

Thanks

推荐答案

您没有做错任何事情,这就是ASP.NET起作用的方式.

如果要执行操作而不重新加载页面,则必须使用AJAX.
You are not doing anything wrong, that is the way ASP.NET functions.

If you want actions without reloading the page then you must use AJAX.


Ajax教程 [^ ]


请参阅我以前对此的回答

防止回发 [
如果这是您想要的,那么您将需要运行某种客户端功能才能在单击按钮时执行某些操作,通常是一些javascript.

否则,如果要运行服务器端代码,只需忽略Page_Load事件中的回发-您可以编写类似
的代码
See my previous answer on this

Preventing postback[^]

You can ''prevent postback'' so the buttons do not call back to the server.

If that''s what you want, you''ll need to run some sort of client side functionality to do something when you click the button, normally some javascript.

Otherwise, if you want server side code to run, just ignore the postbacks in your Page_Load event - you can write code like

if (!Page.IsPostBack)
{
    // Do something here that only happens the first time the page loads
}



然后,只需为按钮创建事件处理程序并相应地编写代码.

您应该使用哪种方法完全取决于您要实现的目标



Then, just create event handlers for your buttons and write code accordingly.

What approach you should use depends entirely on what you''re trying to achieve


这篇关于asp.net-页面重新加载我的遗嘱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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