Click here to Skip to main content
14,664,481 members
Rate this:
Please Sign up or sign in to vote.
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

Rate this:
Please Sign up or sign in to vote.

Solution 1

I think a event will fire on the onClick(), that submit a request to server & get response thats the main thing for postback!
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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" />"); 
      }
   }    
}
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100