我希望每次选中或取消选中复选框(使用 AJAX 中的切换按钮)时都更新页面。但我不能这样做。我尝试用按钮和图像按钮做同样的事情,它们工作得很好(但是当我尝试更新“onclick”功能中的切换按钮时遇到问题),但我想用切换按钮来做到这一点,我尝试了各种意味着在数据绑定和 checkchanged 事件中使用 Page_Load() 但徒劳无功。如何更正代码>
另外我想根据用户的分辨率调整我的背景大小。我该怎么做?我在网上冲浪并尝试用样式表做很多事情,但徒劳无功。请帮忙。
下面给出了来自 Vidual Studio 9 的代码。
默认.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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>Confidentially for 'You'</title>
<link id="Link1" rel="Stylesheet" href="StyleSheet.css" type="text/css" runat="server" />
</head>
<body background="eternal_hearts-normal.jpg" text="white">
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<p align="center" runat="server" id="p1">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />Default Line</p>
<p align="center" id="p2">
<asp:Image ID="Image1" runat="server" EnableViewState="False" />
<asp:CheckBox ID="CheckBox1" runat="server"
oncheckedchanged="Page_Load" ondatabinding="Page_Load" />
<cc1:ToggleButtonExtender ID="CheckBox1_ToggleButtonExtender" runat="server"
Enabled="True" TargetControlID="CheckBox1" ImageWidth="19"
ImageHeight="19" UncheckedImageUrl="ToggleButton_Unchecked.gif"
CheckedImageUrl="ToggleButton_Checked.gif" ondatabinding="Page_Load">
</cc1:ToggleButtonExtender>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:ImageButton ID="ImageButton1" runat="server" Height="23px"
onclick="ImageButton1_Click" Width="30px"
ImageUrl="~/ToggleButton_Unchecked.gif" />
</p>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
默认.aspx.cs:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
static int flag = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (flag == 1)
{
f();
p1.InnerHtml = "Line 1";
}
else if (flag == 2)
{
f();
p1.InnerHtml = "Line 2";
}
else if (flag == 3)
{
f();
p1.InnerHtml = "Line 3";
}
flag++;
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
Page_Load(null, EventArgs.Empty);
}
protected void Button1_Click(object sender, EventArgs e)
{
//if (flag == 0)
//{
// flag++;
// p1.InnerHtml = "Line 1";
//}
//else if (flag == 1)
//{
// flag++;
// p1.InnerHtml = "Line 2";
//}
//else if (flag == 2)
//{
// flag++;
// p1.InnerHtml = "Line 3";
//}
}
protected void f()
{
ImageButton1.ImageUrl = "ToggleButton_Unchecked.gif";
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
}
}
样式表:
img#background
{
min-width: 800px;
width: 100%;
height: auto;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
div.back
{
overflow: hidden;
left: 0;
top: 0;
position: absolute;
z-index: -9999;
}
body
{
text-align: center;
left: 50pt;
right: 50pt;
font-family: 'Bookman Old Style';
position: absolute;
z-index: auto;
width : 100%;
height : 100%;
}