本文介绍了从客户端获取隐藏的字段值,并在ASP .Net中保留值代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

动态地我想得到div元素的高度。在客户端,我获得了价值,并已成功分配到隐藏字段。



Dynamically i want to get the height of the div element. At client side i am getting the value and has been assigned to hidden field successfully.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HomePage.aspx.cs" Inherits="HomePage_New" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title>Home Page</title>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <link rel="stylesheet" href="Css/HomePageStyle.css" type="text/css" />
    <script type="text/javascript" src="Script/jquery_min.js"></script>
    <script type="text/javascript" src="JavaScript/DisableBackSpace.js"></script>
    <script type="text/javascript" src="JavaScript/DisableMouseRightClick.js"></script>

    <script type="text/javascript">
        $(document).ready(function () {
            var varHeight = $('#MainDiv').height();
            $('#maincontentpageframe').height($('#MainDiv').height());

            /*Set the value to Hidden Field*/
            $("input[id=hfMainDiv]").val(varHeight);
            /*alert($('#hfMainDiv').val());*/
        });
    </script>

</head>
<body>
    <form id="form1"  runat="server">
    <div class="header">
        <div class="lefttext">
            Welcome to ATM Claims
        </div>
        <div class="righttext">
            <div>
                <label id="lblLoginUserName"  runat="server"></label> <p>|</p>
            </div>
            <div>
                <a id="lnkHomePage" href="welcomepage.aspx" target="mainFrame">Home</a> <p>|</p>
            </div>
            <div>
                <a id="lnkMyProf" href="myprofile.aspx" target="mainFrame">My profile</a> <p>|</p>
            </div>
            <div>
                <a id="lnkChgPwd" href="ChangePassword.aspx" target="mainFrame">Change password</a> <p>|</p>
            </div>
            <div>
                <a href="">Logout</a>
            </div>
        </div>
    </div>
    <table cellspacing="0" id="main">
        <tr>
            <td class="leftnav">
                <div class="leftnavheader">
                    Menu</div>
                <div class="menu">
                    <iframe src="MenuItem.aspx" frameborder="0" style="height: 91.5%; width: 100%;" name="menuFrame">
                    </iframe>
                </div>
            </td>
            <td class="content">
                <div class="MainFrame" id="MainDiv"  runat="server">
                    <iframe src="WelcomePage.aspx" id="maincontentpageframe" style="width: 99.5%; height: 100%;"

                        frameborder="1" name="mainFrame"  runat="server"></iframe>
                </div>
                <asp:HiddenField ID="hfMainDiv" runat="server" ClientIDMode="Static" Value="23" />
            </td>
        </tr>
    </table>
    <div class="footer">
        <div class="footer_wrap">
            © 2013 | All Rights Reserved.
        </div>
    </div>
    </form>
</body>
</html>









In Code Behind,我正在尝试获取Page Load事件中的值,但价值一无所获。





In Code Behind, i am trying to get the value in Page Load event but value comes nothing.

public partial class HomePage_New : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblLoginUserName.InnerHtml = "";
        Session["HomePageMainDivHeight"] = this.hfMainDiv.Value.ToString();
        if(Session["UserID"] != null)
        {
            lblLoginUserName.InnerHtml = "Hi ! "+Session["UserID"].ToString().Trim();
        }
    }
}

推荐答案




这篇关于从客户端获取隐藏的字段值,并在ASP .Net中保留值代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:36