在ASP.NET开发下动态隐藏文字

来源:互联网 发布:淘宝迅雷会员充值 编辑:程序博客网 时间:2024/04/29 19:45

最近在做软件项目实习这么课的大作业,目的是做一个住院信息管理系统。我们选用的是ASP.NET技术,也就是在VS2008外加SQL SERVER两大软件的协作下完成系统的开发。在开发过程中遇到不少问题,但也学到了不少东西。下面介绍一下动态隐藏文字的技术。

该技术在http://www.bianchengla.com/bbs上面可以看到,如下图所示:

1.在aspx页面中加入如下代码:(在这里我使用了模板页技术,一般情况下放在head中即可)

<asp:Content ID=”head” runat=”server” ContentPlaceHolderID=”head”>
<script language=”JavaScript” type=”text/javascript”>
var col = new Array();
col[15] = ‘#FF0000′;
col[14] = ‘#FF1111′;
col[13] = ‘#FF2222′;
col[12] = ‘#FF3333′;
col[11] = ‘#FF4444′;
col[10] = ‘#FF5555′;
col[9] = ‘#FF6666′;
col[8] = ‘#FF7777′;
col[7] = ‘#FF8888′;
col[6] = ‘#FF9999′;
col[5] = ‘#FFAAAA’;
col[4] = ‘#FFBBBB’;
col[3] = ‘#FFCCCC’;
col[2] = ‘#FFDDDD’;
col[1] = ‘#FFEEEE’;
col[0] = ‘#FFFFFF’;
var i = col.length;
function Over(flag)
{
if(flag==1){i=col.length;td.style.color=’#FF0000′;}
if (i>=0) {i–;td.style.color=col[i];}
setTimeout(‘Over(0)’,300);//渐变
}
</script>
</asp:Content>

2.在窗体上申请一个div空间安放提示字

<div id=”td”><asp:Label ID=”lblMessage” runat=”server” Font-Names=”微软雅黑” Font-Size=”Medium” ></asp:Label></div>

3.在页面对应得cs文件下,加入如下代码:

//颜色变化
protected void MessageBox(string text)
{
lblMessage.Text = text;
Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), “myscript1″, “<script>Over(1) </script>”);
}

4.这时只要再cs文件中的需要使用到的函数下调用此函数即可:(比如这里的提交到数据库中的函数)

//提交到数据库中
protected void btnSubmit_Click(object sender, EventArgs e)
{

try
{
string year = DateTime.Now.Year.ToString();
string month = DateTime.Now.Month.ToString();
string day = DateTime.Now.Day.ToString();
if (Convert.ToInt32(month) < 10)
{
month = “0″ + month;
}

if (Convert.ToInt32(day) < 10)
{
day = “0″ + day;
}
string time = year + “/” + month + “/” + day;
string temperature = txtPatient_Temp.Text.Trim();
string pluse = txtPatient_Pluse.Text.Trim();
string pressure = txtPatient_Pressure.Text.Trim();
string height = txtPatient_Height.Text.Trim();
string weight = txtPatient_Weight.Text.Trim();
if (temperature == “”)
{
temperature = “0″;
}
if (pluse == “”)
pluse = “0″;
if (pressure == “”)
pressure = “0″;
if (height == “”)
height = “0″;
if (weight == “”)
weight = “0″;
DataAccess.sqlcmd = “insert into state(Patient_ID,User_ID,Patient_Temp,Patient_Pressure,Patient_Pluse,Patient_Height,Patient_Weight,Doing_Date,Nurse_Remark,Doing_State) values (‘” + dropPatient_ID.SelectedValue + “‘,’” + DataAccess.Muser_ID + “‘,’” + Convert.ToDouble(temperature) + “‘,’” + Convert.ToDouble(pressure) + “‘,’” + Convert.ToDouble(pluse) + “‘,’” + Convert.ToDouble(height) + “‘,’” + Convert.ToDouble(weight) + “‘,’” + time + “‘,’” + txtNurse_Remark.Text.Trim() + “‘,1)”;
DataAccess.sqlDo();

MessageBox(“提交成功”);
clear();
}
catch
{
MessageBox(“数据提交失败”);
}

}

最终效果如下:

可以看到,基本实现了那个功能,不过如果你的页面不是白色的,可以在java script的代码中修改,颜色值改了就行。自己试试吧。

在此感谢老大提供的技术支持。