C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






__doPostBack function


Posted Date: 12 Aug 2008    Resource Type: Articles    Category: Web Applications
Author: NagarajanMember Level: Gold    
Rating: Points: 10



Here we are going to talk about __doPostBack function.

You can see this __doPostBack function in your asp.net generated HTML code, when you do a "View Source" in the browser

Other than Submit button, all other asp.Net controls use this function to do the postback

Below is how the __doPostBack function looks like in your ASP.NEt generated HTML code

< input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
< input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}


The function takes two arguments eventTarget and eventArgument

The eventTarget contains the ID of the control that causes the postback and the eventArgument contains any additional data associated with the control.

In any asp.net page the two hidden fields, “__EVENTTARGET” and “__EVENTARGUMENT,” are automatically declared. The value of the eventTarget and eventArgument are stored in the hidden fields. The two hidden variables can be accessed from the code behind using the forms or params collection.

The ID of the control which causes the postback is stored in the __EVENTTARGET hidden field, so you can find the control which caused the postback.


protected void Page_Load(object sender, EventArgs e)
{
string controlId1 = Request.Params.Get("__EVENTTARGET");
//OR
string controlId2 = Request.Forms.Get("__EVENTTARGET");
}



Let us see how this function works for a linkbutton.
When you drag a LinkButton from toolbox to webform,
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>

The generated code after rendering generated HTML
<a id="LinkButton1" href="javascript:__doPostBack('LinkButton1','')">LinkButton</a>



You can see the fucntion call "__doPostBack('LinkButton1','')" in href and the argument passed for eventTarget is "LinkButton1" which is the id of the linkbutton control (EventSource)

You can also make a custom call to __doPostBack function and pass id as target and the event information as argument.

Happy Coding !!!





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Postback function  .  Javascript . __doPostBack  .  Javascript  .  Dopostbackfuction  .  Dopostback  .  __doPostBack  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Security settings for Report Server Application
Previous Resource: AJAX with XMLHttpRequest Object
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use