Solved

What's in a postback request?

Posted on 2006-06-30
6
1,527 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

8 Experts available now in Live!

Get 1:1 Help Now