Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript function with __

Status
Not open for further replies.

dbeez

Technical User
Aug 15, 2005
71
0
0
KR
I'm looking at someone's javascript here in my console. The javascript has a
Code:
onclick="javascript:__doPostBack('Pager','2')"
function in it.

The only problem is though, that there is no __doPostBack function on the html or the .js file.

What does the __ mean to javascript ??
Why does the function seem to not be there ? and why does it work without it ?
 
>What does the __ mean to javascript ??
None. Not in javascript as such. It may be a convention for the scripting team.
 
if it's in the .net arch, then why is it denoted as
Code:
javascript:__doPostBack
I don't see this piece of the script being sent server-side, it appears to be a client-side script with no corresponding function. Maybe I'm missing something ??
 
That's probably a good idea Baby*

I know abosolutely nothing about .net, but the code does tend to suggest that this is javascript
Code:
<span class="page" onmouseover="this.style.background='#f7f7f7'" onmouseout="this.style.background=''" onclick="javascript:__doPostBack('Pager','8')">
8
</span>
... unless I'm mistaken ...
 
It is javascript... and it's, of course, not well formed. You do not need the string 'javascript:' in the onclick. But you are correct... a javascript function called __doPostBack() is being called when you click the span - and it is passing 2 strings back to the function.

The function itself will be in an include file. View source of the file using your browser... and look in the head of the file for a <script...></script> that brings in an external javascript file. I would expect it to be there somewhere.

You can alert the function using something like this in the location bar of your browser:
Code:
javascript:alert(window['__doPostBack']);

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
ASP.NET throws that function in there to submit the form on certain events and to alert the server of which element caused the event so the proper server-side event handling code can be executed.

If you view the source of the page after it's parsed, you'll see a block of code like this:
Code:
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="" />
<script language="javascript" type="text/javascript">
<!--
	function __doPostBack(eventTarget, eventArgument) {
		var theform;
		if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
			theform = document.Form1;
		}
		else {
			theform = document.forms["Form1"];
		}
		theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
		theform.__EVENTARGUMENT.value = eventArgument;
		theform.submit();
	}
// -->
</script>

Adam
 
this is a function provided by ASP.NET. the two leading underscores mean nothing syntactically to javascript. this function MUST be included in your page in some manner otherwise it will not work, and the browser will throw an error when the function is called. if you do not see it explicitly defined on the page itself, then it is likely imported in some other javascript include file, or perhaps you are using frames and another frame has imported/defined it.

following BabyJeffy's lead, i went to a website with a .aspx form, typed "javascript:document.write(__doPostBack)" in the address bar, and received
Code:
function __doPostBack(eventTarget, eventArgument) {
	var theform;
	
	if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
		theform = document.Form1;
	} else {
		theform = document.forms.Form1;
	}
	
	theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
	theform.__EVENTARGUMENT.value = eventArgument;
	theform.submit();
}

also, searching MSDN for "__doPostBack" yields many results, one of which is:

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top