Solved

What's in a postback request?

Posted on 2006-06-30
6
1,535 Views
Last Modified: 2012-06-21
I'm looking for links that describe the content of a "postback" request from the client to the server.  I'd like to understand how different types of controls, including hidden fields, send their information back to the server, and how the server recognizes that this is postback that contains such data, and so on.

Any guidance on this would be appreciated.

Thanks!
0
Comment
Question by:codequest
  • 3
  • 2
6 Comments
 
LVL 12

Assisted Solution

by:deanvanrooyen
deanvanrooyen earned 200 total points
ID: 17020254
"...To use automatic postback, you simply need to set the AutoPostBack property of a web control to
true (the default is false, which ensures optimum performance if you don’t need to react to a change
event). When you do, ASP.NET uses the client-side abilities of JavaScript to bridge the gap between
client-side and server-side code.
Here’s how it works: if you create a web page that includes one or more web controls that are
configured to use AutoPostBack, ASP.NET adds a JavaScript function to the rendered HTML page
named __doPostBack(). When called, it triggers a postback, posting the page back to the web server
with all the form information.
ASP.NET also adds two hidden input fields that the __doPostBack() function uses to pass information
back to the server. This information consists of the ID of the control that raised the event
and any additional information that might be relevant. These fields are initially empty, as shown
here:
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
The __doPostBack() function has the responsibility for setting these values with the appropriate
information about the event and then submitting the form. A sample __doPostBack() function is
shown here:
<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform = document.Form1;
theform.__EVENTTARGET.value = eventTarget;
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
</script>
Remember, ASP.NET generates the __doPostBack() function automatically. This code grows
lengthier as you add more AutoPostBack controls to your page, because the event data must be set
for each control.
Finally, any control that has its AutoPostBack property set to true is connected to the
__doPostBack() function using the onClick or onChange attribute. These attributes indicate
what action the browser should take in response to the client-side JavaScript events onClick
and onChange... "

buy pro asp.net 2.0 C# - I dont know if there is a vb version, it a good buy, I got it cheap $25 make sure you get the 2.0
0
 
LVL 2

Author Comment

by:codequest
ID: 17020395
Thanks for the input.   That's very useful in terms of how the postback process works.  Actually, though, I think I really need to see the actual format/structure/content/whatever of the Request transmission string before I'm going to "get it".   I see from your post how ASP.NET uses javasrcript to add stuff to that string...I still don't have a picture of what the resulting request string is going to look like, how it will be structured, what all's in it and so on.  That's what's going to put it together for me.
0
 
LVL 5

Assisted Solution

by:CyberneticsConnoisseur
CyberneticsConnoisseur earned 300 total points
ID: 17020462
Hi

Information is passed through ViewState in Postback in .NET
Viewstate is a collection of name/value pairs, where control's and page itself store information that is persistent among web requests.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/viewstate.asp


http://delphi.about.com/library/weekly/aa051705a.htm

These 2 links have the ans to your question and give more details about the same

Carpe Diem
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:codequest
ID: 17020718
Thanks for the links.   They are great.  Best clear explanation of page cycle I've seen (it's got PICTURES!);  and the stuff on viewstate is something I've needed to wrap my head around for a while.  Actually, I want to take them both home and introduce them to my mother!  But I'm not sure how to explain why I'm seeing two such attractive URL's at the same time... :-)

Sadly, though, I'm still not seeing what the request string looks like.  This comes close:  but it's one of those "object" things, and I'm such a "string" guy...I'm not sure how to raise the kids or anything...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/54d9972a-b6cd-4672-b62a-8793ce8ad335.asp

Perhaps the response string is shy, and does not like to be seen "unencapsulated"...sigh...

Well, so, see, at least my questions are becoming more intelligent  (?)  All good news!  <:*)

0
 
LVL 5

Accepted Solution

by:
CyberneticsConnoisseur earned 300 total points
ID: 17020862
Hi,

As regards your question about how different types of controls send their information back to the server, as mentioned earlier, they are sent through Viewstate which is a serialized base-64 encoded string collection of name/value pairs.

The link also briefs on how you may decode the ViewState

As regards your question about how the server recognizes that this is postback, the isPostBack Property of the page also derives this from the viewstate itself.

As regards the Request Object whose corresponding string representation you
wish to see, an object contains a lot of other details that cant be directly converted to and displayed as a string, but as you may already be knowing ASP.NET provides the functionality to view their values individually.

To that effect I believe, you may not be able to view the corresponding representation and I guess that makes sense too.

Hope this helps

0
 
LVL 2

Author Comment

by:codequest
ID: 17020903
Yes, that helps.   Particularly with respect to the postback.  That kind of like popped something.

I'm getting that a simple request string might look like this:

http://localhost/script/directory/NAMES.ASP?Q=Fred&Q=Sally 

but that a complex request string with serialized vewstate control values could look like anything.  

In particular I was having trouble with a picture that got stuck in my head early in my attempt to understand this material that somehow the entire page (all the html) was involved in the request...which I KNEW couldn't make any sense, because of the transmission cost.   Now that's gone (whew!) and with the seventh re-read of the page cycle (the picture do help) I'm beginning to see how this actually might all work on a real physical computer.

Price of going into consulting in the 90's...

Thanks for the help!



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now