janakiakula
janakiakula

Reputation: 317

__dopostback is not working in javascript function

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>

Upvotes: 3

Views: 6210

Answers (5)

dgarbacz
dgarbacz

Reputation: 962

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

Upvotes: 1

Arun Rana
Arun Rana

Reputation: 8606

Please try to getElementById this way

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

and test it again , it will work..

Upvotes: 0

Jason
Jason

Reputation: 504

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

Upvotes: 0

Icarus
Icarus

Reputation: 63956

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%>"); 

Upvotes: 0

MilkyWayJoe
MilkyWayJoe

Reputation: 9092

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.net/page.aspx/1082/dopostback-function/

Upvotes: 0

Related Questions