有一个页面,是用来显示客户的信息的。但这个页面我想它同时兼顾显示和编辑的功能。可行不?
Dear All,
我现在做ASP.NET开发时遇到一个问题,我有一个页面,是用来显示客户的信息的。但这个页面我想它同时兼顾显示和编辑的功能。
我以前的做法是,当这页面为“显示”状态时,就隐藏所有编辑的控件(一个个地去visible=false),然后把一个个label控件赋值并且显示出来,但这样做的话就会每个页面要写好多行代码去做这些事情。(如果页面比较大的话)
我现在有个想法,我想写个函数,然后直接扫描页面上所有的控件,然后把它们都隐藏,然后又显示它们的内容在它们本来的位置上,我现在已经能扫描页面上所有的控件,但不知道怎么进行下一步了。(比如:就是隐藏该TextBox控件,然后在该TextBox的位置上显示该显示的内容,反之亦然)
foreach (Control i in Page.FindControl( "frmEdit ").Controls)
{
//Response.Write(i.ID + "--- " + i.GetType().FullName);
}
不知道我说得清不清楚。请大家指示。
反正主要目的就是要偷懒,一个页面实现两个功能。:)
Best Regards,
Benny Ng
[解决办法]
据说有Panel这个东西
[解决办法]
把编辑控件用一个Table或者TD框起来,给Table或者TD起个名,id=***,runat=server,然后在后台让那个Table或者TD隐藏不就全隐藏了么?
不知道我领会的对不!
[解决办法]
用panel就对了
实例:
① 进行用户身份检查
② 填写相关的内容
③ 显示你填写的内容
<Html>
<Body bgcolor= "White ">
<center> <H3> 使用Panel控件示例 <Hr> </H3> </center>
<title> 使用Panel控件示例 </title>
<script Language= "VB " runat= "server ">
Sub Page_Load(sender As Object, e As EventArgs)
If Not Page.IsPostBack Then
panel2.Visible = False
panel3.Visible = False
End If
End Sub
Sub Button1_Click(sender As Object, e As EventArgs)
panel1.Visible = False
panel2.Visible = True
End Sub
Sub Button2_Click(sender As Object, e As EventArgs)
panel2.Visible = False
panel3.Visible = True
Span1.InnerHtml = "用户名: " & UserID.Text & " <BR> "
Span1.InnerHtml &= "密码: " & Password.Text & " <BR> "
Span1.InnerHtml &= "姓名: " & Name.Text & " <BR> "
Span1.InnerHtml &= "电话: " & Tel.Text & " <BR> "
Span1.InnerHtml &= "E-mail: " & mail.Text & " <BR> "
Span1.InnerHtml &= "地址: " & Addr.Text & " <P> "
End Sub
Sub Button3_Click(sender As Object, e As EventArgs)
Span1.InnerHtml &= "输入完成! "
Button3.Visible = False
End Sub
</script>
<Form runat= "server ">
<center>
<asp:Panel id= "panel1 " runat= "server ">
<Font Color= "#800000 "> <B> 第一步:请输入用户名和密码 </B> </Font> <Blockquote>
用户名: <asp:TextBox id= "UserID " runat= "server " Text= "kjwang "/> <p>
密码: <asp:TextBox id= "Password " TextMode= "Password "
Text= "kj6688 " runat= "server "/> <p>
<Input Type= "Button " id= "Button1 " value= " 登录 "
OnServerClick= "Button1_Click " runat= "server ">
</Blockquote>
</asp:Panel>
<asp:Panel id= "panel2 " runat= "server ">
<Font Color= "#800000 "> <B> 第二步:请输入用户信息 </B> </Font> <Blockquote>
姓名: <asp:TextBox id= "Name " runat= "server " Text= "小李 "/> <p>
电话: <asp:TextBox id= "Tel " runat= "server " Text= "(023)65355678 " /> <p>
E-mail: <asp:TextBox id= "mail " runat= "server " Text= "jimmy.zh@263.net " /> <p>
地址: <asp:TextBox id= "Addr " runat= "server " Text= "重庆市人民路115# " Size= "40 " /> <p>
<Input Type= "Button " id= "Button2 " value= "申请 "
OnServerClick= "Button2_Click " runat= "server ">
</Blockquote>
</asp:Panel>
<asp:Panel id= "panel3 " runat= "server ">
<Font Color= "#800000 "> <B> 第三步:请确认你的输入 </B> </Font> <Blockquote>
<Span id= "Span1 " runat= "server "/>
<Input Type= "Button " id= "Button3 " value= " 确认 "
OnServerClick= "Button3_Click " runat= "server ">
</Blockquote>
</asp:Panel>
</center>
</form>
<Hr> </body>
</html>
[解决办法]
直接把要显示或隐藏的东西放到PANNEL中,然后只对一个PANNEL的visible属性设置
[解决办法]
可能我理解错了楼主的意思,楼主是不是想先编辑内容,提交以后在同一页面上显示编辑的内容,让人确认一下?
如果是那样的话,你用panel好点