我在webform中的datalist项模板中的textbox加了个javascript脚本onchange,可是它不能正确工作,请教高手!!!部分客户端代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>数据录入</title>
<meta content="True" name="vs_snapToGrid">
<meta content="True" name="vs_showGrid">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body bottomMargin="5" bgColor="#ffffff" topMargin="5" MS_POSITIONING="GridLayout">
<form name="Form1" method="post" action="tjtz_sjsr.aspx" language="javascript" onsubmit="if (!ValidatorOnSubmit()) return false;" id="Form1">
........
<script language="javascript" type="text/javascript" src="/aspnet_client/system_web/1_1_4322/WebUIValidation.js"></script>
.......
<tr>
<td nowrap="nowrap" style="background-color:#99FFFF;">
<span style="width:96px;"><input id="DataList_cw__ctl1_CheckBox_cw" type="checkbox" name="DataList_cw:_ctl1:CheckBox_cw" /><label for="DataList_cw__ctl1_CheckBox_cw">修改</label></span>
<span id="DataList_cw__ctl1_km_name" style="width:248px;">机修产值</span>
<span id="DataList_cw__ctl1_jldw" style="width:80px;">万元</span>
<input name="DataList_cw:_ctl1:TextBox_yue" type="text" id="DataList_cw__ctl1_TextBox_yue" onchange="javascript:this.parentElement.children(0).checked=true;" style="width:114px;" />
<span id="DataList_cw__ctl1_RegularExpressionValidator1" controltovalidate="DataList_cw__ctl1_TextBox_yue" errormessage="RegularExpressionValidator" display="Dynamic" evaluationfunction="RegularExpressionValidatorEvaluateIsValid" validationexpression="([\d-]+\.[\d-]+)|([\d-]+)" style="color:Red;width:98px;display:none;">只能输入数值</span>
<input name="DataList_cw:_ctl1:TextBox_yue_all" type="text" id="DataList_cw__ctl1_TextBox_yue_all" onchange="javascript:this.parentElement.children(0).checked=true;" style="width:114px;" />
<span id="DataList_cw__ctl1_RegularExpressionValidator2" controltovalidate="DataList_cw__ctl1_TextBox_yue_all" errormessage="RegularExpressionValidator" display="Dynamic" evaluationfunction="RegularExpressionValidatorEvaluateIsValid" validationexpression="([\d-]+\.[\d-]+)|([\d-]+)" style="color:Red;display:none;">只能输入数值</span>
</td>
</tr>

解决方案 »

  1.   

    onchange有这个事件吗?
    onblur
      

  2.   

    onchange是服务器端控件TextBox的吧。
      

  3.   

    try:
    aspx:
    --------
    <asp:TextBox id="txtTest" Runat="server"></asp:TextBox>
    cs文件:
    ------------------
    //dataList1_ItemCreated事件
    private void dataList1_ItemCreated(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
    {
    TextBox txt=(TextBox)e.Item.FindControl("txtTest");
                //绑定onchange属性
    if(txt!=null)
      but.Attributes["onchange"]="javascript:this.parentElement.children(0).checked=true;";
    }
      

  4.   

    好像不应有这么复杂,见http://www.microsoft.com/china/msdn/events/webcasts/Webcast/webcasts.mspx
    的ASP.NET开发技巧集锦(一)之同时修改多笔数据
      

  5.   

    if you want to use onchange event for web control textbox, set the AutoPostBack to be true.
      

  6.   

    no,we are failed by this way
      

  7.   

    TextBox好像没有onchange这个事件吧
      

  8.   

    不要纠缠在有没有这个事件了,反正像“BearRui(我有点笨,但我很特别,所以我特别笨!) ”所说的那样为控件添加客户端事件就一定行,我以前做过和这个差不多功能的程序,成功了。