日期:2014-05-18  浏览次数:20452 次

asp.net页面对应的后台cs怎么获取web页面高度
如题

------解决方案--------------------
似乎得用js吧
------解决方案--------------------
通过javascript获得当前窗口页面的宽高度 
网页可见区域宽: document.body.clientWidth; 
网页可见区域高: document.body.clientHeight; 
网页可见区域高: document.body.offsetWidth; //包括边线的宽
网页可见区域高: document.body.offsetHeight; //包括边线的宽
网页正文全文宽: document.body.scrollWidth; 
网页正文全文高: document.body.scrollHeight; 
网页被卷去的高: document.body.scrollTop;
网页被卷去的左: document.body.scrollLeft;
网页正文部分上: window.screenTop; 
网页正文部分左: window.screenLeft; 
屏幕分辨率的高: window.screen.height;
屏幕分辨率的宽: window.screen.width;
屏幕可用工作区高度: window.screen.availHeight; 
屏幕可用工作区宽度: window.screen.availWidth;
------解决方案--------------------
探讨
似乎得用js吧

------解决方案--------------------
探讨
通过javascript获得当前窗口页面的宽高度
网页可见区域宽: document.body.clientWidth;
网页可见区域高: document.body.clientHeight;
网页可见区域高: document.body.offsetWidth; //包括边线的宽
网页可见区域高: document.body.offsetHeight; //包括边线的宽
网页正文全文宽: document.body.scrollWidth;
网页正文全文高: document.body.scrollHeight;
网页被卷去的高: document.body.scrollTop;
网页…

------解决方案--------------------
从页面传回去

HTML code

<form id="form1" runat="server">
  <input type="hidden" name="txBodyClientHeight" id="txBodyClientHeight" runat="server" />
</form>

<script type="text/javascript">
var form = document.forms["form1"];
form.onsubmit = function() {
  this.txBodyClientHeight.value = document.body.clientHeight;
};
</script>

------解决方案--------------------
用Js
------解决方案--------------------
探讨
从页面传回去


HTML code
<form id="form1" runat="server">
<input type="hidden" name="txBodyClientHeight" id="txBodyClientHeight" runat="server" />
</form>

<script type="text/javascript">
var form = document.forms["form1"];
form.onsubmit = function() {
this.txBodyClientHeight.value = document.body.clientHeight;
};
</script>

人家既然问,肯定是业务需要。世界上没有千篇一律的事情。
这个正解。




后台页面:

C# code
if(IsPostBack) {
i…

------解决方案--------------------
1.在ASPX页面中添加HiddenField控件.
<asp:HiddenField ID="HiddenField1" runat="server" />

2.为页面添加启动后javascript脚本.
<form ...>
</form>
<script type="text/javascript">
document.getElementById('<%= HiddenField1.ClientID %>').value = window.screen.height;
</script>

3.在后台代码中获取屏幕高度.
string strHeight = this.HiddenField1.Value;

需要注意的是,应该不能将第3步的代码放在页面事件中. 
(如 page_load 等,因为页面在未完全呈现完之前javascript脚本代码可能还没有执行.)

楼主试下吧,应该可以实现, 我没试过.
 
------解决方案--------------------
探讨
从页面传回去


HTML code
<form id="form1" runat="server">
<input type="hidden" name="txBodyClientHeight" id="txBodyClientHeight" runat="server" />
</form>

<script type="text/javascript">
var form = document.forms["form1"];
form.onsubmit = function() {
this.txBodyClientHeight.value = document.body.