如何在aspx文件内使用JS的属性.
例:
<asp:Panel ID="Panel8" runat="server" ScrollBars="Auto" Height="150px"
 Width="<%# javascript:parseInt(window.screen.width) - 150px %>">我想在Width这处的值设为屏幕宽-150PX,
这个要如何写.
谢谢.

解决方案 »

  1.   

    Width="javascript:parseInt(window.screen.width) - 150"> 
      

  2.   

    这个。。你应该先得到这个值,再赋给width吧
      

  3.   

    .net不可以直接获取宽度么`一定要用jS?
      

  4.   

    我就是想直接在aspx文件中设定它的值.
    应该只能用JS吧?
      

  5.   

    在aspx文件内怎么取?
    请求详解.谢谢.
      

  6.   

    <%# ... %> 这个都是绑定服务端的数据或代码表达式的
    要想用脚本实现,可以            <script type="text/javascript" for="window" event="onload">
                    var p = document.getElementById('<%= Panel8.ClientID %>');
                    var wcw = window.screen.width;
                    p.style.width = parseInt((wcw - 150)).toString() + "px";
                </script>祝你好运!
      

  7.   

    试试下面代码
    //.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" %><!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></head>
    <body>
        <form id="form1" runat="server">
        <asp:Panel id="aaa" runat ="server" Height="127px" BackColor ="Blue" >
        test
        </asp:Panel>
        <script type ="text/javascript" >
            var p_aaa = document.getElementById(getClientId().aaa);
            p_aaa.style.width = parseInt(window.screen.width) - 350 +"px";
        </script>
        </form>
    </body>
    </html>//.cs
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;namespace WebApplication4
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //向客户端增加脚本对象,把服务端组件的客户端对应ID传到客户端(服务器端id与客户端id不同)
                string script = @"<script type='text/javascript'>
                 getClientId = function() {
                 return { aaa:'" + aaa.ClientID +
                    "'}} </script> ";            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "getClientId", script);        }
        }
    }
    http://www.mybuffet.cn
      

  8.   

    呵呵 感觉有点本末倒置。因为本身来说 像Panel 这些服务器空间都是再后台生成的。所有你这个问题
    因为是 使用javascript来设置 Panel 的样式更好些  
      

  9.   

    给你看下我写的   <asp:GridView ID="gvDataList" runat="server" AutoGenerateColumns="False" OnPageIndexChanging="gvDataList_PageIndexChanging" OnRowDataBound="gvDataList_RowDataBound" OnRowUpdating="gvDataList_RowUpdating" >
    这个是 GridView  我像设置他的样式属性 因为这个样式 很多页面都要用 所以
    我直接再后面 加上 javascript来设置他的样式 
     var vartable=document.getElementById("gvDataList");
            if(vartable!=null)
            {
                 
                vartable.className="table";
    }这个样子就可以了 你的那个肯定也是一样的