简体   繁体   English

为什么在HTML按钮执行C#代码时重新加载页面

[英]why page is reloading when html button executing c# code

I have html form which default value is display:none. 我有HTML表单,其默认值为display:none。
Im showing it with jquery. 我用jQuery显示它。
There is button with C# code behind. 后面有带C#代码的按钮。 When its executing page is reloading and my form is disappearing(display:none). 当其执行页面重新加载并且我的表单消失时(显示:无)。 How i can execute c# code without page reload ? 我如何在不重新加载页面的情况下执行C#代码?

Your c# code is server side and the page reloads to be able to call it. 您的C#代码在服务器端,页面会重新加载以进行调用。 If you don't want that you'll need to use some AJAX. 如果您不想这样做,则需要使用一些AJAX。

See this tutorial: http://www.asp.net/web-forms/videos/aspnet-ajax/how-do-i-make-client-side-network-callbacks-with-aspnet-ajax 请参阅本教程: http : //www.asp.net/web-forms/videos/aspnet-ajax/how-do-i-make-client-side-network-callbacks-with-aspnet-ajax

Is all of your code in the Page_Load section? 您的所有代码都在Page_Load部分中吗? Each time you make a callback the Page_Load runs. 每次您进行回调时,都会运行Page_Load。 To stop certain things from happening each time you make a callback you can put them in something like 要阻止每次回调时发生的某些事情,可以将它们放入类似

if (!Page.IsCallback && !Page.IsPostBack)
{
    //this code will only be run the first time the page is loaded.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM