admin管理员组

文章数量:1431037

am calling __dopostback function in javascript while closing event of browser but its not working in Chrome.

the same function is working in IE

can any one give me the solution.

<script type="text/javascript" language="javascript"> 
function doUnload() 
{ 
 var btnlogout = document.getElementById("ctl00_lbtn_Logout"); alert(btnlogout);   
 __doPostBack(btnlogout, ''); 
} 
</script>

am calling __dopostback function in javascript while closing event of browser but its not working in Chrome.

the same function is working in IE

can any one give me the solution.

<script type="text/javascript" language="javascript"> 
function doUnload() 
{ 
 var btnlogout = document.getElementById("ctl00_lbtn_Logout"); alert(btnlogout);   
 __doPostBack(btnlogout, ''); 
} 
</script>
Share Improve this question edited Dec 1, 2011 at 6:03 janakiakula asked Dec 1, 2011 at 5:42 janakiakulajanakiakula 3171 gold badge5 silver badges14 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 1

When doing a __doPostBack, you need to pass the control's UniqueID via javascript. ClientID will not work.

I think you should be passing the btnlogout id as string (not sure if you have to remove the ctl00 thing since it's a child control) as the function expects text and it is probably resolved during the request on the server..

Take a look at this article: http://wiki.asp/page.aspx/1082/dopostback-function/

Just do:

btnlogout.click(); 

since you already have a reference to the button and, by the way, don't get the element the way you are doing it; do this instead:

var btnlogout = document.getElementById("<%=btn_Logout.ClientID%>"); 

dopostback(clientID, args)'s first parameter must be a control's clientid, it is a string , not object (of course string is object ) .. in your case , i assume that is 'ctl00_lbtn_Logout', pass the right params like :

__doPostBack('<%= downloadUp.ClientID %>', current_index);

if your control is server side control, change 'downloadUp' to your control's id , else you just need pass the id

Please try to getElementById this way

var btnlogout = document.getElementById('<%= lbtn_Logout.ClientID %>'); 
alert(btnlogout)

and test it again , it will work..

本文标签: aspnetdopostback is not working in javascript functionStack Overflow