Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 14-Mar-12 18:48pm
v2

I think a event will fire on the onClick(), that submit a request to server & get response thats the main thing for postback!
 
Share this answer
 
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:
C#
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" />"); 
      }
   }    
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900