How to call jQuery function from C #

I would like to fadein and exit the div after executing some code. This jQuery function works fine when using the onclientclick property. But, Unable to call it from C #.

JS:

function Confirm()
{
 $(".saved").fadeIn(500).fadeOut(500);
}

WITH#

protected void btnsave_click(object sender, Eventargs e)
{
  //some code
  upd.update();
  ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Confirm", 
   "<script type='text/javascript'>Confirm();</script>", true);
}

HTML:

<asp:updatepanel id="upd" runat="server" updatemode="conditional">
 <triggers>
  <asp:asyncpostbacktrigger controlid="btnsave" eventname="click"/>
 </triggers>
 <contenttemplate>
  <div style="position:relative">
    <span class="saved">Record Saved</span>
    <asp:gridview....../>
  </div>
  <asp:button id="btnsave" runat="server" text="save" onclick="btnsave_click"/>
 </contenttemplate>
</asp:updatepanel>

CSS

.saved
{
  position:absolute;
  background:green;
  margin:0 auto;
  width:100px;
  height:30px;
  visibility:hidden;
}
+4
source share
3 answers

WITH#

protected void btn_click(object sender, Eventargs e)
{
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
}

JS:

<script>
   function Confirm()
   {
      $(".saved").fadeIn(500).fadeOut(500);
   }
</script>

Change Upgrade Code

WITH#

protected void btn_click(object sender, Eventargs e)
{
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Confirm();", true);
}

JS:

<script>
    $(document).ready(function () {

       function Confirm() {
           $(".saved").fadeIn(500).fadeOut(500);
       };
    });
</script>
+5
source

When using asynchronous mail messages, it is useful to understand the events that you can actually process on the client side (aspx file).

(jquery, javascript) , , pageLoaded . , javascript :

function pageLoad(sender, args) { 
    $(".saved").fadeIn(500).fadeOut(500);
}

this MSDN .

,


,

pageLoad , , this MSDN, Animating Panels, - :

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);
    }
}
+1

...

ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "Confirm();", true);
0

Source: https://habr.com/ru/post/1530368/


All Articles