完成ASP.NET页面加载后运行javascript函数 [英] Run a javascript function after ASP.NET page load is completed

查看:77
本文介绍了完成ASP.NET页面加载后运行javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在页面完成后从ASP.NET代码中运行一个javascript函数。

I need to run a javascript function from ASP.NET code behind AFTER the page is completed.

到目前为止我已经使用过这段代码,但它返回undefined 因为当javascript函数被触发时,隐藏字段没有填充值。

I've used this code so far but it returns "undefined" because the hidden field is not filled with the value when javascript function is fired.

我该怎么办?提前完成。

What should I do? Thanx in advance.

ASPX:

  <asp:HiddenField runat="server" ID="ColorHiddenField" ClientIDMode="Static" Value="0" />

Javascript:

Javascript:

    function HandleColors() {
        alert($('#<%= ColorHiddenField.ClientID %>').val());
    }

代码背后:

  ColorHiddenField.Value = item.Color;
  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "HandleColors();", true);


推荐答案

尝试下面的代码,它使用jQuery document.ready 在页面加载后运行脚本:

try code below, it uses jQuery document.ready to run your script after page loads:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", "$(function () { HandleColors(); });", true);

这篇关于完成ASP.NET页面加载后运行javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆