I would like to fadein and out a div after performing some code. This JQuery function is working fine when using the button\'s onclientclick property. But, Unable to call it
When using asynchronous post backs is good to understand the events that you can actually handle on the client side (aspx file).
If you want to execute some client function (jquery, javascript) after an asynchronous post back has been made, I suggest using the pageLoaded event on the client side. So your javascript will be something like the following:
function pageLoad(sender, args) {
$(".saved").fadeIn(500).fadeOut(500);
}
For more information please refer to this MSDN page on the Event Order for Common Scenarios section.
Hope this helps
Edit after comment to add filter example
To filter logic in the pageLoad event depending on the element that raised the event, as stated in this MSDN page, on the Animating Panels section, you can do something like this:
var postbackElement;
function beginRequest(sender, args) {
postbackElement = args.get_postBackElement();
}
function pageLoaded(sender, args) {
if (typeof(postbackElement) === "undefined") {
return;
}
else if (postbackElement.id.toLowerCase().indexOf('btnsave') > -1) {
$(".saved").fadeIn(500).fadeOut(500);
}
}
Try this...
ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "Confirm();", true);
C#
protected void btn_click(object sender, Eventargs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
}
<script>
function Confirm()
{
$(".saved").fadeIn(500).fadeOut(500);
}
</script>
C#
protected void btn_click(object sender, Eventargs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
}
<script>
$(document).ready(function () {
function Confirm() {
$(".saved").fadeIn(500).fadeOut(500);
};
});
</script>