asp.net的listView控件:<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="插入" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="清除" />
</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
</td>
<td>
<asp:TextBox ID="locationTextBox" runat="server"
Text='<%# Bind("location") %>' />
</td>
<td>
//下面的ID用于获取到该TextBox
<asp:TextBox ID="LogoTextBox_Logo" runat="server" Text='<%# Bind("Logo") %>' />
</td>
<td>
<asp:TextBox ID="sequenceTextBox" runat="server"
Text='<%# Bind("sequence") %>' />
</td>
<td>
<asp:TextBox ID="createrTextBox" runat="server" Text='<%# Bind("creater") %>' />
</td>
<td>
<asp:DropDownList ID="ddlInsertTemplate" runat="server">
<asp:ListItem value="Text">文本链接</asp:ListItem>
<asp:ListItem value="pic">图片</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</InsertItemTemplate>
此处是后台代码:protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType==ListViewItemType.InsertItem)
{
//这里根据下拉控件的ID获取到了下拉控件的对象
DropDownList ddl = (DropDownList)e.Item.FindControl("ddlInsertTemplate");
//这里也是找到插入数据时要获取的textBox的对象,红色字体的ID和上面<InsertItemTemplate>的TextBox的Id是一样的
TextBox tb = (TextBox)e.Item.FindControl("LogoTextBox_Logo");
//下面红色部分生成的ID和在HTML页面渲染成的ID不一样。求解
ddl.Attributes["onchange"] = "changeVisible(this,"+tb.ClientID+")";
}
}
后台代码中tb对象是不是空,并且生成的ClientId和在页面生成的ID不一样
以下是渲染成的HTML的部分代码
<tr style="">
<td>
<input type="submit" name="ListView1$ctrl4$InsertButton" value="插入" id="ListView1_InsertButton" />
<input type="submit" name="ListView1$ctrl4$CancelButton" value="清除" id="ListView1_CancelButton" />
</td>
<td>
<input name="ListView1$ctrl4$NameTextBox" type="text" id="ListView1_NameTextBox" />
</td>
<td>
<input name="ListView1$ctrl4$locationTextBox" type="text" id="ListView1_locationTextBox" />
</td>
<td>
<input name="ListView1$ctrl4$LogoTextBox_Logo" type="text" id="ListView1_LogoTextBox_Logo" />
</td>
<td>
<input name="ListView1$ctrl4$sequenceTextBox" type="text" id="ListView1_sequenceTextBox" />
</td>
<td>
<input name="ListView1$ctrl4$createrTextBox" type="text" id="ListView1_createrTextBox" />
</td>
<td>
<select name="ListView1$ctrl4$ddlInsertTemplate" id="ListView1_ddlInsertTemplate" onchange="changeVisible(this,ctrl4_LogoTextBox_Logo)">//这里生成的clientId和绿色部分的不一样
<option value="Text">文本链接</option>
<option value="pic">图片</option>
</select>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="插入" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="清除" />
</td>
<td>
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
</td>
<td>
<asp:TextBox ID="locationTextBox" runat="server"
Text='<%# Bind("location") %>' />
</td>
<td>
//下面的ID用于获取到该TextBox
<asp:TextBox ID="LogoTextBox_Logo" runat="server" Text='<%# Bind("Logo") %>' />
</td>
<td>
<asp:TextBox ID="sequenceTextBox" runat="server"
Text='<%# Bind("sequence") %>' />
</td>
<td>
<asp:TextBox ID="createrTextBox" runat="server" Text='<%# Bind("creater") %>' />
</td>
<td>
<asp:DropDownList ID="ddlInsertTemplate" runat="server">
<asp:ListItem value="Text">文本链接</asp:ListItem>
<asp:ListItem value="pic">图片</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</InsertItemTemplate>
此处是后台代码:protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType==ListViewItemType.InsertItem)
{
//这里根据下拉控件的ID获取到了下拉控件的对象
DropDownList ddl = (DropDownList)e.Item.FindControl("ddlInsertTemplate");
//这里也是找到插入数据时要获取的textBox的对象,红色字体的ID和上面<InsertItemTemplate>的TextBox的Id是一样的
TextBox tb = (TextBox)e.Item.FindControl("LogoTextBox_Logo");
//下面红色部分生成的ID和在HTML页面渲染成的ID不一样。求解
ddl.Attributes["onchange"] = "changeVisible(this,"+tb.ClientID+")";
}
}
后台代码中tb对象是不是空,并且生成的ClientId和在页面生成的ID不一样
以下是渲染成的HTML的部分代码
<tr style="">
<td>
<input type="submit" name="ListView1$ctrl4$InsertButton" value="插入" id="ListView1_InsertButton" />
<input type="submit" name="ListView1$ctrl4$CancelButton" value="清除" id="ListView1_CancelButton" />
</td>
<td>
<input name="ListView1$ctrl4$NameTextBox" type="text" id="ListView1_NameTextBox" />
</td>
<td>
<input name="ListView1$ctrl4$locationTextBox" type="text" id="ListView1_locationTextBox" />
</td>
<td>
<input name="ListView1$ctrl4$LogoTextBox_Logo" type="text" id="ListView1_LogoTextBox_Logo" />
</td>
<td>
<input name="ListView1$ctrl4$sequenceTextBox" type="text" id="ListView1_sequenceTextBox" />
</td>
<td>
<input name="ListView1$ctrl4$createrTextBox" type="text" id="ListView1_createrTextBox" />
</td>
<td>
<select name="ListView1$ctrl4$ddlInsertTemplate" id="ListView1_ddlInsertTemplate" onchange="changeVisible(this,ctrl4_LogoTextBox_Logo)">//这里生成的clientId和绿色部分的不一样
<option value="Text">文本链接</option>
<option value="pic">图片</option>
</select>
解决方案 »
- 讨论:防注入有没有同时过滤所有危险字符
- 一条正则
- 218.0.0.0/16。这个IP什么意思啊?怎么转换?在线等!
- 怎么用变量控制表格颜色啊?
- 经理刚下达了个任务,请高手指教,万分感谢!!
- VSS管理asp.net项目,打开.aspx文件时总是自动提示签出
- include 的动态使用问题
- 急求javascript引用webservice.htc操作WebService的问题,多帖求救了,解答者4帖分全给!!!!
- 请教如何让.net处理Big-5编码的繁体字??
- asp.net如何实现图片压缩!如何实现文件传输!
- 关于asp.net转换成PDF文件的问题
- datalist中textbox取值问题,急
ddl.Attributes["onchange"] = "changeVisible(this,"+tb.ClientID+")";
应该改成
ddl.Attributes["onchange"] = "changeVisible(this,'"+tb.ClientID+"')";
这个我试了下,在ItemDataBound事件中,是不是走insertItemTemplate这个模板的,所以js函数不会被绑定到插入事件中的下拉控件里。
这个也不行,加了单引号,渲染到HTML里单引号会被渲染成'的符号。