Understanding the JavaScript __doPostBack Function
page 5 of 7
by Mohammad Azam
Feedback
Average Rating: 
Views (Total / Last 10 Days): 254612/ 2927

Passing Arguments

If you look closely at the __doPostBack function you will notice that the second argument is called the eventArgument.  You can allow controls to pass arguments to the doPostBack function.  Check out the code below.

Listing 6 – Passing arguments to the __doPostBack function

<input type="button" id="Button2" value="Press me" onclick="DoPostBack()" />
<script language="javascript" type="text/javascript">
 
function DoPostBack() 
{
  __doPostBack('Button2','My Argument');     
}
 
</script>
string passedArgument = Request.Params.Get("__EVENTARGUMENT");

Analysis

The “Button2” when clicked fires the DoPostBack function which in turn calls the __doPostBack.  The __doPostBack function contains two arguments, eventTarget and eventArgument.  The eventTarget is “Button2” and the eventArgument is “My Argument.”  Later, in the C# code behind, I have accessed the eventArgument using the Request.Params collection.  The passedArgument variable will contain the value “My Argument.”


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 6 and 2 and type the answer here:

User Comments

Title: iu9up0oi   
Name: ghyg
Date: 11/20/2009 6:54:33 PM
Comment:
akssl,s.aaLDLKÑF-´W-´´L
FGKLGASDLHÑASÑLHÑSÑKÑDÑPK
DASWFKLGSLL.ELJLSPHJLÑSÑJ
SCLSDAFKCDSLKFDLSÑLSGDGH
FDSÑLSDÑKÑLDSJÁSÑKLFUÑÑY
PRETGPRRPEOHH`PKRÑJUÑED
XÑSA`DÑSA´GLHÑJ´´J´GÑJ
Title: simple and concise   
Name: mryildiz
Date: 11/17/2009 9:12:57 AM
Comment:
thanks a lot, very effective article...
waiting for more...
:)
Title: Very Good   
Name: Visvabalaji
Date: 11/12/2009 9:32:47 AM
Comment:
Very good article with simple examples.

Thanks :)
Title: Thank you very much.   
Name: sD_b
Date: 10/19/2009 10:28:55 AM
Comment:
It's a nice artical. :-)
Title: Nice Article   
Name: Md. Mostafijur Rahman
Date: 10/13/2009 2:08:12 AM
Comment:
It's nice one to clear concept on Javascript Postback
Title: Thank You =)   
Name: Brian
Date: 8/20/2009 11:23:36 AM
Comment:
One of the best technical articles on the internet...thank you =)
Title: good   
Name: suntzu
Date: 8/6/2009 4:32:02 AM
Comment:
I think it can help me out of difficulty
Title: Good article   
Name: sasmita
Date: 8/5/2009 2:28:52 AM
Comment:
Very good explanation. It helped me a lot.
Title: Mr   
Name: Kamal
Date: 7/28/2009 2:06:38 AM
Comment:
doPostback is not working in 2.0 web page... as in 1.1 web page its working... Could any one suggest u r idea...

Regards,
Kamal
Title: mrs   
Name: joebek
Date: 7/16/2009 6:14:28 AM
Comment:
Am have javasascript_doPostBack('dnn$ctr412$registraion$linkBottonRegistartion';) on my system pleas what can i do to correct it
Title: Thanks   
Name: Platipibo
Date: 7/11/2009 7:15:24 AM
Comment:
thanks a lot,
It really works
Title: @Understanding the JavaScript __doPostBack Function   
Name: Abhishek Shrivastava
Date: 7/10/2009 2:10:07 PM
Comment:
Nice article...I have searched around 70+ links in google to understand postback...but none of them explained it so clearly.
thanks for sharing the knowledge!
Title: Fantastic Explanation   
Name: Sanjay
Date: 7/2/2009 8:11:46 AM
Comment:
Fantastic explanation. I was very happy reading this article. Keep it Up Azam...............
Title: Very good article   
Name: Jigar
Date: 6/26/2009 8:33:07 AM
Comment:
Very nice & useful article. Keep up the good work.
Title: Jonny J Jacob   
Name: See title
Date: 6/1/2009 3:32:01 PM
Comment:
i HAS PROBLEM TOO WIT THE POST BACKER
Title: investor   
Name: arun kapoor
Date: 5/18/2009 6:16:04 AM
Comment:
i m using javascript:_dopostback for stock statement, but now these pages are not open tell me
Title: Mr.   
Name: Walt Handel
Date: 4/25/2009 6:19:44 PM
Comment:
How do I get rid of Javascript doPostBack0;? Its screwing up my computer.
Title: Short, Concise, no BS   
Name: Jax
Date: 4/1/2009 10:51:20 AM
Comment:
Perfectly done and right to the point. Thanks.
Title: roman   
Name: mehmet
Date: 3/6/2009 5:50:20 AM
Comment:
very nice!
Title: javascript:_dopostback   
Name: Asween
Date: 2/9/2009 3:15:29 PM
Comment:
Wonderful article, explains the whole concept in a very succinct and concise way.
Title: javascript:_dopostback   
Name: prashant
Date: 2/9/2009 3:12:36 AM
Comment:
i have a problem that is javascript:_dopostback in my thinclient machine.
Title: do post back   
Name: noushad
Date: 1/21/2009 1:31:21 AM
Comment:
Very nice article, its very easy to learn with this type of articles, thank you
Title: Nice Article   
Name: G. Vijay Bhargav
Date: 12/17/2008 2:17:49 AM
Comment:
Nice article - Is there any way to customise the __doPostBack function.
Title: Thanks   
Name: Ali
Date: 11/21/2008 10:57:20 AM
Comment:
Good article. It helps a lot.
Title: function __doPostBack   
Name: vinay
Date: 11/17/2008 4:11:45 AM
Comment:
I got an error in function __doPostBack function
(object not support this property or method)

please give the solution.
Title: Good article   
Name: Ratndeep
Date: 11/11/2008 1:51:32 AM
Comment:
Thanks for this good article...
Title: Thanks Azam   
Name: Pablo A Castillo
Date: 11/10/2008 11:38:45 PM
Comment:
thanks for this article, very useful for me.
Title: Nice stuff   
Name: ALTAF
Date: 11/8/2008 12:40:45 PM
Comment:
Thx, It clears the doubts in my mind.
Title: Really great   
Name: Murali
Date: 11/6/2008 9:38:28 AM
Comment:
This article saved my skin. Thnq
Title: _doPostBack caused me to postback all the time   
Name: Benny
Date: 10/24/2008 7:24:05 AM
Comment:
Hi,

im using the __doPostBack method, but it caused the page to keep on postBack non-stop. how to stop it ?
Title: java script for email   
Name: vamshi
Date: 10/19/2008 10:58:08 PM
Comment:
i want to use java script for email validation please hel me
Title: calender control   
Name: siva srinivas
Date: 9/7/2008 11:46:05 PM
Comment:
how to select a calender control into my ui
Title: Problem with this function   
Name: Srinivas
Date: 7/16/2008 3:23:50 AM
Comment:
\
\
\
\
Title: SharePoint   
Name: Shams
Date: 7/7/2008 5:19:16 PM
Comment:
I am new to this function __doPostBack
Title: SharePoint   
Name: Roberto
Date: 7/3/2008 9:26:57 PM
Comment:
I've been able to use __doPostBack within SharePoint. This function when called from client-side script and combined with a custom web part makes it possible to get past some SharePoint limitations.

http://www.tributarysoft.com
Title: Security message   
Name: MV
Date: 6/10/2008 11:48:35 AM
Comment:
I am getting a security message whenever the dopostback is called for a calendar control from a button. Can I send you the message and see if you have come across this message before?

Thanks. MV
Title: pagination   
Name: john
Date: 5/25/2008 4:46:32 AM
Comment:
don't make each paragraph on a new page to increase your stats or you will lose viewers like you will lose me if i continue seeing this
Title: excellent explanation   
Name: Sandesh Kadam
Date: 4/10/2008 9:20:49 AM
Comment:
Greetings, This is nice peice of explanation for the postback. But for certain reason i didn't find it helpful in my situation as its not covered in the article. And i post this message to all the champs, if possible please tel me how would we do the same postback excersie having the forms action allready defined? i shall wait to read from you guys...

Sandesh
Title: example   
Name: name_example
Date: 4/8/2008 4:03:52 AM
Comment:
it example
Title: i want script like this   
Name: anmoldeep
Date: 2/26/2008 9:09:20 AM
Comment:
javascript:__doPostBack('dnn$dnnSOLPARTMENU$ctldnnSOLPARTMENU','56')
Title: er controls.   
Name: er controls.
Date: 2/26/2008 5:27:53 AM
Comment:
er controls.
Title: __doPostBack()   
Name: Ramesh Ramalingam
Date: 2/17/2008 3:09:11 AM
Comment:
Nice artical... It is pretty clear...
Title: __doPostBack()   
Name: amit
Date: 2/10/2008 3:39:09 AM
Comment:
I want to know this
Title: __doPostBack()   
Name: Rudra
Date: 1/29/2008 4:19:31 AM
Comment:
Good artical
Title: Improve   
Name: Muthu
Date: 1/17/2008 6:44:28 AM
Comment:
u do u have next button for such a same article
Title: Can i call the __doPostBack in a href   
Name: Vimal
Date: 1/9/2008 3:52:48 AM
Comment:
Hai i tried to call the __doPostBack event in a href from client side script, but i got an error 'object expected'.

var link = document.createElement('A');
link.setAttribute('href','javascript:__doPostback("TESTTgt","TESTArg")');
Title: Mr   
Name: Ajit
Date: 1/3/2008 10:05:41 AM
Comment:
Very nice article, very easy to understand.
Title: cool   
Name: Big Fat Al
Date: 12/19/2007 8:18:10 PM
Comment:
Cheers Mate - nice one - only takes a few minutes to gain some clarity but too often we rush on ahead without stopping to think. Thanks for the quick n easy read, especially the bit about buttons not calling __DoPostBack... solved my problem for the morning.. onto the next one!
Title: Thnx   
Name: Yusuf Squires
Date: 12/4/2007 3:12:51 PM
Comment:
Really helpful. Thnx!!!!
Title: __doPostBack('btnCntrl','')   
Name: Nac
Date: 11/28/2007 6:13:09 AM
Comment:
if this called in javascript function alone it works fine
but if function contains some other javascript statements
before this stmt, it is not working properly,
may I know why this is happening??
Title: Fantastic Article   
Name: The Computer Doctor
Date: 11/26/2007 11:21:26 AM
Comment:
A very very good article.
Title: Good article   
Name: Everett Liu
Date: 11/20/2007 4:23:11 AM
Comment:
I am a new comer, I like this, I will come here again.
Title: Lame.   
Name: Brittany
Date: 11/9/2007 5:23:04 AM
Comment:
Wow, that told me absolutely nothing.

Tell me straight to the point how to make it so javascript won't be lame and let me view all internet pages.

That's all I want to know.
Title: Google Map control   
Name: Moe
Date: 11/5/2007 1:44:59 AM
Comment:
HI, is there a .net control which can load gmarkers dynamically ? like this site http://www.publicbar.com
does ?
Title: I HATE JAVA   
Name: APPLE
Date: 10/4/2007 8:47:18 PM
Comment:
I HATE JAVA EVERY TIME I CLICK SOMETHING IT POPS UP I GET PISSED OF
Title: BACK   
Name: MARLYN
Date: 10/4/2007 4:50:10 PM
Comment:
its good java
Title: photos   
Name: GF
Date: 10/4/2007 4:45:10 PM
Comment:
the java thing keeps poping up every time i want to change my default and it will not let me delete my pictures and when i click fix java it does not work
Title: comments   
Name: navjot
Date: 9/13/2007 5:22:52 AM
Comment:
dis was very informative article......good work!!!!
Title: What's the difference between...   
Name: JS
Date: 8/21/2007 2:45:15 PM
Comment:
my drop down list wont change because when I debug, in the _doPostBack function, !theForm.onSubmit returns false and (theForm.onsubmit() returns false.

what's the difference between onSubmit and onSubmit()?
Title: Mr.   
Name: Amd
Date: 8/13/2007 4:45:01 AM
Comment:
Nice!!!!!!!!
Title: how to change event argument of linkbutton via javascript   
Name: anjali
Date: 7/21/2007 11:57:12 AM
Comment:
i have a link button which has CommandArgument property set to "lbOne". When i click link button i want to change its CommandArgument property to "lbTwo" via javascript(not in code behind) How can i do that? Any help greatly appreciated...
Title: Excellent Article!   
Name: Stuart
Date: 7/17/2007 8:15:20 AM
Comment:
Thanks for a very informative article. This not only helped me to understand the __EVENTARGUMENT but has given me enough food for thought to solve an issue I've been having with postbacks when trying to use a modulpopupextender.

Keep up the good work!
Title: Calling __doPostBack without link button or autopostback set to true   
Name: Josh
Date: 7/12/2007 8:35:39 PM
Comment:
If you want to use __doPostBack without setting the autopostback to true or without adding a link button add this bit of code to your pageload. This will create the reference to the function for you

Page.GetPostBackEventReference(this);
Title: dal   
Name: M. Kausar
Date: 7/12/2007 1:58:34 AM
Comment:
this good
Title: Shrivastav   
Name: Deepak
Date: 6/18/2007 9:36:11 AM
Comment:
Very good way to teach the things.Good artical,but could have been into more depth.
Title: Good artical But I Need Some other help please   
Name: Spatel
Date: 6/1/2007 2:57:21 AM
Comment:
I am Using Asp.net2.0.I wan't to get Control type in Java Script So please tell me How I Know that Control Which comes in Java Script is Textbox,DropDown,or any other.

Thanks in Advance.
Title: thanks   
Name: pravin nair
Date: 5/28/2007 10:29:47 AM
Comment:
It was a really good article.I really understood the concepts of __doPostBack();
Title: Thankyou   
Name: Si
Date: 5/25/2007 9:54:10 AM
Comment:
Thanks for a clear and concise explanation of __doPostBack():)
Title: Need help   
Name: Priya
Date: 4/26/2007 5:39:10 AM
Comment:
Good article. Can you tell me how do I do a postback on another page to reflect some chnages when I click one button from my current active page?
Title: Waste   
Name: Shi
Date: 4/19/2007 5:45:07 AM
Comment:
Waste article, no use
Title: heeee   
Name: heeee
Date: 3/30/2007 4:39:24 PM
Comment:
let me know how to use __doPostback with out keeping link button or autopostback='true' on dropdownlist
Title: javascript:__doPostBack('ViewFinancialAid','')   
Name: Gary Lagstrom Jr
Date: 3/14/2007 7:09:57 AM
Comment:
This pop-up is blocked on my financial dispersion awards for my graduate program at Walden University. It is an image button that shows dispesement dates for my student loans. I need to be able to see this image. Even though I have the pop-up function disabled it still blocks the image. What do I do?

Send reply to:
gary_lagstrom@hotmail.com

Thank-you for your time:)
Title: Good Article it may help in my projet   
Name: sandesh
Date: 2/17/2007 1:21:22 AM
Comment:
Good Article it may help in my projet,

But where i will get the answers of these questions asked by others

Plz give me reply at sandesh_daddi@rediffmail.com
Title: Why does it use javascript:setTimeout   
Name: Ornit
Date: 11/5/2006 5:40:52 AM
Comment:
Why does it use javascript:setTimeout for exceuting _doPostBack instead of calling it directly?
Title: javascript:-doPostBack(imageLogin Button)   
Name: Sarah
Date: 10/20/2006 12:46:09 PM
Comment:
What does that mean? Am trying to get into my web mail and cannot. That is the message that I get. I do not have a computer background and my ISP Tech is no help. Can you explain that message to me? Thank you
Title: Find out eventtarget and eventargument on clientside?   
Name: nico
Date: 9/26/2006 7:11:01 AM
Comment:
Hi,

just found your article. thank you for your work. i'd need to find out eventtarget and eventargument on the client side. we are doing some validation on the side, every time the form is submitted. in asp 1.1 wh had to overwrite dopostback AND onsubmit. now in .net 2.0 onsubmit is called every time and we don't need to overwrite dopostback anymore. unfortunately we need to know, which control caused the postback. do you have an idea how to get this information within onsubmit?

regards
nico
Title: Thanks   
Name: AzamSharp
Date: 8/17/2006 2:25:00 PM
Comment:
I am glad that you liked the article!
Title: MCAD   
Name: Gene Naden
Date: 8/17/2006 2:21:48 PM
Comment:
The article on Understanding the __doPostBack function was very helpful.
Title: Great!!   
Name: Irfan
Date: 8/1/2006 5:47:11 AM
Comment:
Great..atleast we got an idea of javascript dopostback function..

Nice Explaination
Title: Thanks   
Name: Rob
Date: 8/1/2006 5:13:55 AM
Comment:
I've been searching for a way to send client-side inputs (through a DIV/contentEditable) blended on a page with server-side controls for inclusion in a database. The ability to send 'My Argument' (or whatever text) through this method works great.

Thanks
Title: How to fin button that caused postback   
Name: me
Date: 7/14/2006 5:46:36 PM
Comment:
Pravin:
This is where you can find out which button caused the postback:
http://www.ryanfarley.com/blog/archive/2005/03/11/1886.aspx
Title: How can I cause a submit button callback????   
Name: Deepak
Date: 7/13/2006 1:58:20 AM
Comment:
Hi
Conider the following code
[CODE]
&lt;asp:button id=btnServer OnClick=btnServer_Click /&gt;

[/CODE]
Question:
I want to write a client side function (replace ...) such that it allows to call the server side btnServer_Click function. How can I do that?
Title: Firefox problem   
Name: Scott Hooper
Date: 6/29/2006 11:26:10 PM
Comment:
This works beautifully in IE, but doesn't work for firefox. I am pretty sure it's a problem with the syntax of:
theForm.__EVENTTARGET.value = eventTarget;
Any suggestions on how to correct?
Thanks,
sfhooper@expectra.com.au
Title: Finding button that caused postback   
Name: Pravin Singh
Date: 6/29/2006 7:43:57 AM
Comment:
In LISTING 5, you iterated through the form collection for finding the button control but if for example my page has multiple submit buttons - how do we find out which button caused the postback?

Product Spotlight
Product Spotlight 






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 11/22/2009 5:20:14 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search