|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
ASP最大的缺点在于网络的安全性和可靠性,企业将经营数据放在开放的平台上,最大的担忧就是如何保证这些数据不被其他人破坏。假如刚从ASP过渡到ASPX的程序员,多数会埋怨ASPX天生的客户端元素的ID,太长了!假如要在客户端剧本中利用,如使用:
以下为援用的内容:
document.getElementById(Repeater1_ctl00_Button1)
这一类的体例来援用,十分不便利。
想像一下,你想天生如上的界面,然后在鼠标在Button上mousemove时,改动其后面对应的文本框中的笔墨,格局为:helloworld+该Button的ID+--+newDate().valueOf()
先不要管,这个有甚么用,在甚么中央用,起首,你怎样完成呢?
我的完成办法就是如题目所言,用服务器控件来凑合它们,只需我们来选择一个符合的思绪:假定我们有一个服务器控件,经由过程给控件指定两个相干联的控件(这里就是Buton和TextBox),我们在客户端为这两个控件,分离设置自界说的属性来间接指向另外一个控件。
假如有了另外一个控件的援用,我们就能够在button的实例中,间接失掉相干联的TextBox的援用,而绕开getElementById().
先看一下该服务端控件的利用:
以下为援用的内容:<div>
<asp:RepeaterID="Repeater1"runat="server">
<ItemTemplate>
<asp:TextBoxID="TextBox1"runat="server"Width="445px"></asp:TextBox>
<asp:ButtonID="Button1"runat="server"Text="Button"onmousemove="returnbutton_onmousemove(this,event)"/>
<cc1:WebControlLinkerID="WebControlLinker1"runat="server"WebControlFirst="Button1"WebControlSecond="TextBox1"/>
</ItemTemplate>
</asp:Repeater>
</div>
注重一下cc1:WebControlLinker的WebControlFirst="Button1"WebControlSecond="TextBox1"我们设置了两联系关系的控件.
它们会在页面输入时,天生上面的代码:
页面出现:
以下为援用的内容:<div>
<inputname="Repeater1$ctl00$TextBox1"type="text"id="Repeater1_ctl00_TextBox1"style="width:445px;"/>
<inputtype="submit"name="Repeater1$ctl00$Button1"value="Button"id="Repeater1_ctl00_Button1"onmousemove="returnbutton_onmousemove(this,event)"/>
<spanid="Repeater1_ctl00_WebControlLinker1"></span>
<inputname="Repeater1$ctl01$TextBox1"type="text"id="Repeater1_ctl01_TextBox1"style="width:445px;"/>
<inputtype="submit"name="Repeater1$ctl01$Button1"value="Button"id="Repeater1_ctl01_Button1"onmousemove="returnbutton_onmousemove(this,event)"/>
<spanid="Repeater1_ctl01_WebControlLinker1"></span>
<inputname="Repeater1$ctl02$TextBox1"type="text"id="Repeater1_ctl02_TextBox1"style="width:445px;"/>
<inputtype="submit"name="Repeater1$ctl02$Button1"value="Button"id="Repeater1_ctl02_Button1"onmousemove="returnbutton_onmousemove(this,event)"/>
<spanid="Repeater1_ctl02_WebControlLinker1"></span>
<inputname="Repeater1$ctl03$TextBox1"type="text"id="Repeater1_ctl03_TextBox1"style="width:445px;"/>
<inputtype="submit"name="Repeater1$ctl03$Button1"value="Button"id="Repeater1_ctl03_Button1"onmousemove="returnbutton_onmousemove(this,event)"/>
<spanid="Repeater1_ctl03_WebControlLinker1"></span>
<inputname="Repeater1$ctl04$TextBox1"type="text"id="Repeater1_ctl04_TextBox1"style="width:445px;"/>
<inputtype="submit"name="Repeater1$ctl04$Button1"value="Button"id="Repeater1_ctl04_Button1"onmousemove="returnbutton_onmousemove(this,event)"/>
<spanid="Repeater1_ctl04_WebControlLinker1"></span>
</div>
以下为援用的内容:<scripttype="text/javascript">
<!--
document.getElementById(Repeater1_ctl00_Button1).setAttribute(TextBox1,document.getElementById(Repeater1_ctl00_TextBox1));
document.getElementById(Repeater1_ctl00_TextBox1).setAttribute(Button1,document.getElementById(Repeater1_ctl00_Button1));
document.getElementById(Repeater1_ctl01_Button1).setAttribute(TextBox1,document.getElementById(Repeater1_ctl01_TextBox1));
document.getElementById(Repeater1_ctl01_TextBox1).setAttribute(Button1,document.getElementById(Repeater1_ctl01_Button1));
document.getElementById(Repeater1_ctl02_Button1).setAttribute(TextBox1,document.getElementById(Repeater1_ctl02_TextBox1));
document.getElementById(Repeater1_ctl02_TextBox1).setAttribute(Button1,document.getElementById(Repeater1_ctl02_Button1));
document.getElementById(Repeater1_ctl03_Button1).setAttribute(TextBox1,document.getElementById(Repeater1_ctl03_TextBox1));
document.getElementById(Repeater1_ctl03_TextBox1).setAttribute(Button1,document.getElementById(Repeater1_ctl03_Button1));
document.getElementById(Repeater1_ctl04_Button1).setAttribute(TextBox1,document.getElementById(Repeater1_ctl04_TextBox1));
document.getElementById(Repeater1_ctl04_TextBox1).setAttribute(Button1,document.getElementById(Repeater1_ctl04_Button1));
//-->
</script>
有了下面的器材,,我们要实行的剧本就能够复杂的写成如许:以下为援用的内容:
<head><title>
UntitledPage
</title>
<scripttype="text/javascript">
functionbutton_onmousemove(obj,e)
{
obj.TextBox1.value="helloworld"+obj.TextBox1.Button1.id+--+newDate().valueOf();;
}
</script>
</head>obj.TextBox1.value这类体例,会见,也挺爽吧?
请作者接洽本站,实时附注您的姓名,接洽邮箱:Post@chinaz.com。
ASP在国内异常流行,因为国内大多使用的是盗版的Windows和盗版的SQLServer,而ASP+COM+SQLServer实际上也是一种不错的搭配,其性能也不输于PHP+MYSQL,特别是Windows系统和SQLServer都有图形界面,比APACHE和MYSQL易于维护,因此对于不重视知识产权的国家来说也是一种不错的选择。 |
|