在设计时如何将hiddenfield值分配给javascript函数 [英] How to assign hiddenfield value to a javascript function at design

查看:42
本文介绍了在设计时如何将hiddenfield值分配给javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的页面上有一个ASP标签,标签后有一个隐藏的输入字段.
我的标签具有"onclick"事件,该事件带有一个采用单个参数的javascript函数.
现在,我想在"Asp:Label"定义时将隐藏字段的值分配/传递给javascript函数.

我只是尝试这样的事情:

Hi,

I have a ASP Label on my page, and a hidden input field following my label.
My label has ''onclick'' event attached with a javascript function which takes a single argument.
Now I want to assign/pass value of hidden field into javascript function while "Asp:Label" definition.

I''m just trying something like this:

<asp:Label ID="lbl1" runat="server" Text="" Visible="true" onclick="changePage('<%=hid1201.Value%>')" meta:resourcekey="lbl1Resource1"></asp:Label>
                                                    <asp:HiddenField  runat="server" ID="hid1201" />



我无法获得结果,任何人都可以帮助我.

提前谢谢.

Sri.



I''m unable to get the result, can anybody help me out.

Thanks in advance.

Sri.

推荐答案

您已经注意到asp:Label没有"onClick"客户端事件.
因此,解决此问题的最佳方法是使用JQuery,它已经成为包括Microsoft在内的许多公司的标准JavaScript框架.


试试此代码,它可以工作.

As you already noticed the asp:Label does not have "onClick" client side event.
So the best way to handle this is to use JQuery, which has already become the standard JavaScript framework for many companies including Microsoft.


Try this code, it works.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Label ID="lbl1" runat="server" Text="My Label Text"></asp:Label>
    <asp:HiddenField runat="server" ID="hid1201" Value="My Hidden Value" />
    </form>

    <script language="javascript" type="text/javascript">


(函数(){
(document).ready(function () {


(" #<%= lbl1.ClientID%>").click(
("#<%=lbl1.ClientID %>").click(function () { alert(


这篇关于在设计时如何将hiddenfield值分配给javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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