Sorry. This may be very simple for you…
I have a Button in my Web Form. In the Browser, I opened the Fire Bug and saw the following HTML corresponding to the Button
<input type="submit" id="btn" value="Upload" name="btn">
Following is my Button HTML at server side…
<asp:Button ID="btn" runat="server" Text="Upload" OnClick="ButtonClick" />
So When the user hits the button, which is right now at the client side, invokes the Server side handler of the button.
My Question is how is this mapping being done internally, I meant, user is hitting the button at client side and this is executing the code at server side? Because button is no more available at server. Page is downloaded and now it is at Client side. right?
In windows Form application, this is very simple to understand this concept as the Button Event and handler are both lying in the same file and there is no Client-Server concept.
Everything is bound up in the page’s ViewState, which is passed as an argument during the PostBack. So in effect, the button continues to “live” and various arguments are passed along with it. If you look at the source of your generated page, you’ll see a
__doPostBackJavaScript call which handles the actual event that is occurring. This is sent in the form of an http POST request, and the ViewState provides any “stateful” information to the page’s server-side code.There is a lot more going on here, and I recommend you research the Asp.Net Page Lifecycle to understand it more thoroughly.