Button postback from html page source into the postback and event processing

Posted by Karthime under ASP.NET on 4/3/2012 | Points: 10 | Views : 1257 | Status : [Member] | Replies : 5
Hi, recently one interview question asked to me, that is if i have the server control like <asp:button id="button1" runat="server" Text="Insert" OnClick="button1_Click"/> in the web page, during the runtime if i right click on the page and view the page source of the page in mozilla firefox browser, in the page source the button control source display in the html format like <input type="submit" name="Button1" value="Submit" id="Button1" /> here it doesn't have the onclick property, then how the event is fired when i click the button, and page is postback, and how the html page source is performing the button click event, even it doesn't have runat="server" and also onclick property in the page source. if anyone knows answer for it please help me

A.Karthi


Responses

Posted by: Rajni.Shekhar on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
when you have a button in your page, it will render as submit type button in source file (view source) and in form tag check there would be method="post" and action="yourpage.aspx" will be shown, cause submit button takes action for action attribute of form tag.

even in IE also, when you have a button same as you written, it will not show onclick even.
Try it, take a button on a page and click event.
when you run the page, check view source, you will not found onclick event there. (I have checked in IE)
Check form tag, there would be action property of form tag.

Thanks,
Rajni Shekhar

Karthime, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthime on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Rajni Shekar, Thank you for your reply, i checked it has the action property in the form tag, how the onclick event gets fired

A.Karthi

Karthime, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
with the help of button id which is present in both side that is client or server so server check that id and type if submit with this information ,it make call to event

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Karthime, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 4/3/2012 [Member] Bronze | Points: 25

Up
0
Down
in asp.net page life cycle, before page rendering done, all control's event called and save the view state and before unload page rendering event called which render HTML elements to page.
First it process the server controls then render HTML elements.

For more info:

http://msdn.microsoft.com/en-us/library/ms178472.aspx

Thanks,
Rajni Shekhar

Karthime, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthime on: 4/6/2012 [Member] Starter | Points: 25

Up
0
Down
If i have many button controls in the page, how in the server side identifies which submit button causes the onclick event, and how it makes call the event for the corresponding button id

A.Karthi

Karthime, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response