为什么页面回发并在单击按钮时通知服务器 [英] why the page is post back and inform to the server when the button click

查看:63
本文介绍了为什么页面回发并在单击按钮时通知服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击按钮控件时,该页面已回发到服务器中,为什么会发生这种情况,这是什么原因,如果我想为其他控件(文本框,下拉列表)提供回发,将自动回传设置为true.但是在按钮控件中不是必需的,除了用于向服务器发回的事件fire(onclick)以外,按钮控件中还存在其他哪些东西

Hi, When i click the button control the page is postback into the server, why this is happening, what is the reason for this, if i want to give the postback for the other controls(textbox, dropdownlist) i need to set the autopostback true. but it is not necessary in button control, what is the extra things reside in the button control except event fire(onclick) for postback into the server than others

推荐答案

I认为事件将在onClick()上触发,该事件将向服务器提交请求并获得响应,这是回发的主要内容!
I think a event will fire on the onClick(), that submit a request to server & get response thats the main thing for postback!


因为.NET Framework按钮基类导致回发,因此捕获了回发事件,并在服务器上引发Click事件.以下是自定义Button控件的示例代码:
Because .NET framework button base class causes postback, captures the postback event, and raises a Click event on the server. Here is the sample code to customize Button control:
namespace CustomControls 
{  
   public class MyButton: Control, IPostBackEventHandler 
   {     
      // Defines the Click event.
      public event EventHandler Click;
      
      // Invokes delegates registered with the Click event.
      protected virtual void OnClick(EventArgs e) 
      {     
         if (Click != null) 
         {
            Click(this, e);
         }  
      }
      
      // Method of IPostBackEventHandler that raises change events.
      public void RaisePostBackEvent(string eventArgument)
      {     
         OnClick(EventArgs.Empty);
      }
      
      protected override void Render(HtmlTextWriter output) 
      {     
         output.Write("<input type="submit" name=" + this.UniqueID + <br mode=" hold=" />            " value="Click Me" />"); 
      }
   }    
}


这篇关于为什么页面回发并在单击按钮时通知服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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