Click here to Skip to main content
15,887,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm running through a problem of client side scripting in ASP.Net. I've following code added for a button to show up and image on client side and go up server side:
btnSearch.Attributes.Add("onclick", "document.getElementById('preloaderImage').style.visibility='visible';");

This is working fine but only when I click the button first time, not on second and further clicks. I appreciate any help !!

Best regards,
Sunny.
Posted
Updated 18-Sep-12 23:40pm
v2
Comments
deepakaitr12345 19-Sep-12 5:34am    
where did you write the above statements.
if the control goes to the server side after showing this then.definatly next time it will not call.must write the code on proper place.

Thanks
Sunny_Kumar_ 19-Sep-12 5:43am    
I've written this code on Page_Load()
deepakaitr12345 19-Sep-12 5:47am    
correct but under the Page.IsPostBack or outside.???


Thanks
Sunny_Kumar_ 19-Sep-12 5:57am    
I've tried both, putting inside IsPostBack & outside of it.

Thanks
Mohd Imran Saifi 19-Sep-12 6:10am    
what are you trying to do; image show/hide or what?

1 solution

Can't you add javascript on ASPX page for button.

That way you will not need to think worry adding attribute on code-behind.

Also you can write J-Query on document.ready which will be executed once page is loaded fully so you can hide the image,
 
Share this answer
 
v3
Comments
Sunny_Kumar_ 19-Sep-12 7:04am    
thanks nikunjmochi,

I did it myself just a minute back... I just added this code inside <body> tag:

<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
var elem = args.get_postBackElement();
ManagePreloader('visible');
}
function EndRequestHandler(sender, args) {
ManagePreloader('hidden');
}
function ManagePreloader(state) {
document.getElementById('preloaderImage').style.visibility = state;
}

</script>

Just wanted to share how I handled this :)
Sunny_Kumar_ 19-Sep-12 7:04am    
now it works like a charm !!
nikunjmochi 19-Sep-12 7:47am    
great!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900