AlwaysVisibleControlExtender控件

AlwaysVisibleControlExtender控件直译出来就是“始终显示”。个人感觉这个控件貌似有点多余,不知道究竟有多大用处。既便如此,我们还是得了解了解它。
我们把浏览器的窗口若分成3行3列的话,AlwaysVisibleControlExtender控件便可以让我们要显示的信息在这分出来的9个方框的任何一个中出现。下面来看看具体如何使用它。
首先创建一个ASP.NET AJAX-Enabled Web Site,打开默认创建好的Default.aspx文件并进入设计模式。
你将会看到一个ScriptManager控件在上面,千万可别把它删除哦,删了就不能使用AJAX了。
向页面中拖入一个UpdatePanel控件,再分别向UpdatePanel中拖入一个panel和一个AlwaysVisibleControlExtender控件。在pnael中我们可以写一些信息,例如:
尼克技术博客
学习笔记
,接下来选中AlwaysVisibleControlExtender控件并修改其属性TargetControlID为写有信息的那个panel。
接下来再向UpdatePanel中拖入一个DropDownList同时启用DropDownList的AutoPostBack属性,并为其增加如下几项值:

 
  1. <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
  2.                     <asp:ListItem Value="11">默认</asp:ListItem>
  3.                     <asp:ListItem Value="00">左上</asp:ListItem>
  4.                     <asp:ListItem Value="01">中上</asp:ListItem>
  5.                     <asp:ListItem Value="02">右上</asp:ListItem>
  6.                     <asp:ListItem Value="10">左中</asp:ListItem>
  7.                     <asp:ListItem Value="11">中中</asp:ListItem>
  8.                     <asp:ListItem Value="12">右中</asp:ListItem>
  9.                     <asp:ListItem Value="20">左下</asp:ListItem>
  10.                     <asp:ListItem Value="21">中下</asp:ListItem>
  11.                     <asp:ListItem Value="22">右下</asp:ListItem>
  12. </asp:DropDownList>

 

双击DropDownList的SelectedIndexChanged事件,并写入如下代码:

 
  1. switch (this.DropDownList1.SelectedValue[0])
  2.         {
  3.             case ’0′:
  4.                 avce.VerticalSide = VerticalSide.Top;
  5.                 break;
  6.             case ’1′:
  7.                 avce.VerticalSide = VerticalSide.Middle;
  8.                 break;
  9.             case ’2′:
  10.                 avce.VerticalSide = VerticalSide.Bottom;
  11.                 break;
  12.             default:
  13.    &n
    bsp;            avce.VerticalSide = VerticalSide.Middle;
  14.                 return;
  15.         }
  16.         switch (this.DropDownList1.SelectedValue[1])
  17.         {
  18.             case ’0′:
  19.                 avce.HorizontalSide = HorizontalSide.Left;
  20.                 break;
  21.             case ’1′:
  22.                 avce.HorizontalSide = HorizontalSide.Center;
  23.                 break;
  24.             case ’2′:
  25.                 avce.HorizontalSide = HorizontalSide.Right;
  26.                 break;
  27.             default:
  28.                 avce.HorizontalSide = HorizontalSide.Center;
  29.                 return;
  30.         }

 

现在你可以保存并运行这个AJAX了,在下拉框中选中你要它显示的位置,它就会根据你的指令走了。


如果你觉得你的信息框不好看,那么你可以在panel的属性中对其样式进行修改。
至于DropDownList1.SelectedValue[0]其意就是取出当前选中的值的索引为0的字符,例如Value="11"那么这里取出的便是“1”,之后对其进行判断,进而改变panel在网页中的位置。


除非另有声明,本站遵循【署名-非商业性使用-相同方式共享 3.0 共享协议】授权。

转载原创文章请注明,转载自:Neeke[http://www.ineeke.com]

本文链接: http://www.ineeke.com/archives/AlwaysVisibleControlExtender/

2008年10月19日 | 归档于 ASP.NET | 没有评论
本文目前尚无任何评论.

发表评论

XHTML: 您可以使用这些标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
n:-zy n:-zr n:-zan n:-xf n:-wx n:-tz n:-tt n:-ts n:-sy n:-st n:-ss n:-sk n:-qd n:-pz n:-lh n:-kun n:-ku n:-hx n:-hd n:-gt n:-gg n:-bz

NOTICE: You should type some Chinese word (like “你好”) in your comment to pass the spam-check, thanks for your patience!