A question about the event model in ASP.NET


T

Tony Johansson

Hello!

If I have an asp:button on a page and the user click this button on the page
how will this click event be stored on the way to the server where the event
handler is executed that is bind with this button ?

Is eveying stored in this viewstate or I'm I wrong ?

//Tony
 
Ad

Advertisements

C

Chris

Hello!

If I have an asp:button on a page and the user click this button on the page
how will this click event be stored on the way to the server where the event
handler is executed that is bind with this button ?

Is eveying stored in this viewstate or I'm I wrong ?

//Tony

I believe it's by means of a javascript function called "__doPostback"
with some arguments. When this postback is received, the server script
will know from the arguments passed which handler will need to be
called.
 
Ad

Advertisements

T

Tony Johansson

Chris said:
I believe it's by means of a javascript function called "__doPostback"
with some arguments. When this postback is received, the server script
will know from the arguments passed which handler will need to be
called.

Here I have an example of three files there is no java script called
__doPostback as you say.
The first part market **start_1** and **end_1** is the aspx page
The second part is the code behind file I have market is with **start_2**
and **end_2**. Here I have an event handler called Button1_Click for the
asp:Button that I have dragged from the toolbox.
The third and the last part is the file I get if I right click on the page
when it is displayed in the brower to get the HTML code that is sent to the
clent side. I just right click and select show source. This part is marked
with **start_3** and **end_3**.

So my question is still relevant
If I have an asp:button on a page and the user click this button on the page
how will this click event be stored on the way to the server where the event
handler is executed that is bind with this button ?

Is eveying stored in this viewstate or I'm I wrong ?

//**start_1**
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button"
onclick="Button1_Click" />
</div>
</form>
</body>
</html>
**end_1**

**start_2**
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }

protected void Button1_Click(object sender, EventArgs e)
{ }
}
**end_2**


**start_3**
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default2.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUKMTQ2OTkzNDMyMWRkJNIytRcJYXgAUCMp+nl+RIAVWdA=" />
</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION"
value="/wEWAgK19OCRBwKM54rGBtbjgO/UgjqECwuRHEEa9DJSuhnp" />
</div>
<div>
<input type="submit" name="Button1" value="Button" id="Button1"
style="color:White;background-color:Red;font-weight:bold;" />
</div>
</form>
</body>
</html>
**end_3**

//Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top