在updatepanel的部分回发之后执行javascript ?

时间:2022-08-25 18:47:03

I have a page that add tree file script to it .

我有一个向它添加树文件脚本的页面。

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="js/easing.js"></script>

I have a updatepanel with a dropdownlist. When run SelectedIndexChanged event (partial postback of an updatepanel), don't execute javascript .

我有一个带有下拉列表的updatepanel。当运行SelectedIndexChanged事件(updatepanel的部分回发)时,不要执行javascript。

5 个解决方案

#1


23  

Use

使用

function pageLoad(sender, args) {

  InitialiseSettings();
}

function InitialiseSettings(){
    // replace your DOM Loaded settings here. 
    // If you already have document.ready event, 
    // just take the function part and replace here. 
    // Not with document.ready 
    $(element).slideUp(1000, method, callback});

    $(element).slideUp({
                   duration: 1000, 
                   easing: method, 
                   complete: callback});
}

or try with add_endRequest event handler:

或者试试add_endRequest事件处理器:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(InitialiseSettings)

Update

更新

Better move the all the code from document.ready to InitialiseSettings function and pass it to pageLoaded event

最好将所有代码从文档中移动。准备好初始化保存函数并将其传递给分页事件

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitialiseSettings)

Code Example:

代码示例:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitialiseSettings)

#2


19  

To run your javascript in full and partial postbacks, put your javascript code into javascript pageLoad() function.

要完整地运行javascript和部分回发,请将javascript代码放到javascript pageLoad()函数中。

function pageLoad()
{
   //your javascript code
}

Example:

例子:

function pageLoad() {

    $(':submit').click(function () {
        CommodityArray();
    });
    $('#btn_image').click(function () {
       CommodityArray();
    });
    $(".repHeader").disableSelection();

    CommodityArray();
}

Hope it helps! :)

希望它可以帮助!:)

#3


7  

You have to use following code after your update panel.

您必须在更新面板之后使用以下代码。

<script type="text/javascript" language="javascript">
var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
pageRequestManager.add_endRequest(NewCharacterCount);
</script>

where NewCharacterCount is your javascript function name.

NewCharacterCount是javascript函数名。

Read this article Sys.WebForms.PageRequestManager endRequest Event Hope it may help you.

阅读本文Sys.WebForms。PageRequestManager endRequest事件希望能对您有所帮助。

#4


0  

If you are using UpdatePanel and you want to call a javascript function after content refresh in update panel, you can use below way to do it easily. In Page body tag , call a function RefreshContent()

如果您正在使用UpdatePanel,并且希望在更新面板中的内容刷新之后调用一个javascript函数,那么可以使用下面的方法来轻松实现。在页面主体标记中,调用函数RefreshContent()

<body onload="RefreshContent()">

<script type="text/javascript">
  function RefreshContent()
  {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
  }

  function EndRequestHandler()
  {
    alert("Add your logic here" );
  }
</script>

Reference link http://www.infoa2z.com/asp.net/how-to-call-javascript-function-after-an-updatepanel-asychronous-request-to-asp.net-page

参考链接:http://www.infoa2z.com/asp.net/how-to-call-javascript-function-after-an-updatepanel-asychronous-request-to-asp.net-page

#5


0  

You can use PageRequestManager client events. The sender parameter will contain the information you need. For example one could do this:

您可以使用PageRequestManager客户端事件。sender参数将包含所需的信息。例如,我们可以这样做:

// Register event handler
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);

/// Executed when all page content is refreshed, full page or async postback: https://msdn.microsoft.com/en-us/library/bb397523.aspx
function pageLoaded(sender, args) {
    var isPostBack = sender.get_isInAsyncPostBack();
    if(!isPostBack) return;

    // PostBack logic here.
}

#1


23  

Use

使用

function pageLoad(sender, args) {

  InitialiseSettings();
}

function InitialiseSettings(){
    // replace your DOM Loaded settings here. 
    // If you already have document.ready event, 
    // just take the function part and replace here. 
    // Not with document.ready 
    $(element).slideUp(1000, method, callback});

    $(element).slideUp({
                   duration: 1000, 
                   easing: method, 
                   complete: callback});
}

or try with add_endRequest event handler:

或者试试add_endRequest事件处理器:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(InitialiseSettings)

Update

更新

Better move the all the code from document.ready to InitialiseSettings function and pass it to pageLoaded event

最好将所有代码从文档中移动。准备好初始化保存函数并将其传递给分页事件

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitialiseSettings)

Code Example:

代码示例:

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InitialiseSettings)

#2


19  

To run your javascript in full and partial postbacks, put your javascript code into javascript pageLoad() function.

要完整地运行javascript和部分回发,请将javascript代码放到javascript pageLoad()函数中。

function pageLoad()
{
   //your javascript code
}

Example:

例子:

function pageLoad() {

    $(':submit').click(function () {
        CommodityArray();
    });
    $('#btn_image').click(function () {
       CommodityArray();
    });
    $(".repHeader").disableSelection();

    CommodityArray();
}

Hope it helps! :)

希望它可以帮助!:)

#3


7  

You have to use following code after your update panel.

您必须在更新面板之后使用以下代码。

<script type="text/javascript" language="javascript">
var pageRequestManager = Sys.WebForms.PageRequestManager.getInstance();
pageRequestManager.add_endRequest(NewCharacterCount);
</script>

where NewCharacterCount is your javascript function name.

NewCharacterCount是javascript函数名。

Read this article Sys.WebForms.PageRequestManager endRequest Event Hope it may help you.

阅读本文Sys.WebForms。PageRequestManager endRequest事件希望能对您有所帮助。

#4


0  

If you are using UpdatePanel and you want to call a javascript function after content refresh in update panel, you can use below way to do it easily. In Page body tag , call a function RefreshContent()

如果您正在使用UpdatePanel,并且希望在更新面板中的内容刷新之后调用一个javascript函数,那么可以使用下面的方法来轻松实现。在页面主体标记中,调用函数RefreshContent()

<body onload="RefreshContent()">

<script type="text/javascript">
  function RefreshContent()
  {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
  }

  function EndRequestHandler()
  {
    alert("Add your logic here" );
  }
</script>

Reference link http://www.infoa2z.com/asp.net/how-to-call-javascript-function-after-an-updatepanel-asychronous-request-to-asp.net-page

参考链接:http://www.infoa2z.com/asp.net/how-to-call-javascript-function-after-an-updatepanel-asychronous-request-to-asp.net-page

#5


0  

You can use PageRequestManager client events. The sender parameter will contain the information you need. For example one could do this:

您可以使用PageRequestManager客户端事件。sender参数将包含所需的信息。例如,我们可以这样做:

// Register event handler
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);

/// Executed when all page content is refreshed, full page or async postback: https://msdn.microsoft.com/en-us/library/bb397523.aspx
function pageLoaded(sender, args) {
    var isPostBack = sender.get_isInAsyncPostBack();
    if(!isPostBack) return;

    // PostBack logic here.
}