类似这种由于用户控件中的子控件ID只有在使用此用户控件时才能确定,因此我想一个办法就是用户控件本身公开一个属性,就是调用叶面给此用户控件的ID,用户控件取得此ID以后就可以正确无误的生成对应的Script脚本,还有就是通过遍历查找,由于用户控件都是以[用户调用ID_控件ID]形式生成到客户端,通过遍历查找后缀是[_控件ID]这种形式的标签也有一定的可行性,但是也不好,另外一种则是依赖于UI的DOM查找,通常就是通过鼠标的时间来得到触发时间的控件编号,然后依赖于DOM来找到其他控件编号,(比如这些控件都是处在同一个表格中)这种办法就是要依赖于UI,如果UI改变,也就是说如果控件顺序改变的话都必须要重新修改Script.
瞎说了一通,不知道说明白了没有,我也同样期待更好的办法.:)
瞎说了一通,不知道说明白了没有,我也同样期待更好的办法.:)
document.all.<%=TextBox1.ClientID%>
得到的是它在客户端的ID,其它的操作没有什么不同。不知我的理解对不对2、ListBox有个属性Selected,设为True就是选上了。
键盘上下移可以先捕捉键盘事件,做个循环改变每行的Selected属性就行了。
/// <summary>
/// 设置控件的焦点
/// </summary>
/// <param name="strControlName">要获取焦点的控件名称</param>
static public void SetFocus(Page webform,string strControlName)
{
if (strControlName != "")
{
if(!webform.IsStartupScriptRegistered(strControlName + "SetFocus"))
{
string strScript;
strScript="<script defer language=javascript>function window.onload() {document.all['" + strControlName + "'].focus();}</script>";
//下一句对网页可用,对模式窗口会提示出错,因为模式窗口控件还没有实例化
//strScript="<script defer language=javascript>document.all['dmc_txtDepartMentCode'].focus()</script>";
webform.RegisterStartupScript(strControlName + "SetFocus",strScript);
}
}
}
//调用设置焦点
SetFocus(this.Page,你的控件.ClientID);选定某项
设置
下拉控件.SelectedIndex= n;
或
下拉控件.SelectedValue = dr["no"].ToString();
所以用ClientID,自动转换为解释后的名字
下拉控件.SelectedValue = "值";这个值一定要在语句 下拉控件.SelectedValue = "值" 之前加载
(文本框ID为"txtID")WebControl txt1=(WebControl)Page.FindControl("txtID");
txt1.Attributes.Add("onmouseover","return this.focus();");但是将此文本框放在用户控件中,这种效果应该如何实现呢?
string me=this.ClientID;
WebControl txt1=(WebControl)Page.FindControl(me).FindControl("txtID");
txt1.Attributes.Add("onmouseover","return txtfocus(this);");
<script language="javascript">
function txtfocus(txt)
{
txt.focus();
txt.select();
}
</script>
http://expert.csdn.net/Expert/topic/2543/2543412.xml?temp=.6896479
一起结帐,共计几百分的呀!