 悬赏园豆:15
                [已解决问题] 
            
                    解决于 2014-01-15 19:48
                悬赏园豆:15
                [已解决问题] 
            
                    解决于 2014-01-15 19:48 
                 
        我在LISTVIEW的ItemCreated事件中为一个DropDownList添加onchange事件,传入另一个TextBox的CLIENTID,但是在客户端的HTML中查看,传递的'变为' 不知道是什么原因?具体的代码如下:
C#代码:
protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem || e.Item.ItemType == ListViewItemType.InsertItem)
            {
                DropDownList ddLinktype = (DropDownList)e.Item.FindControl("ddlLinkType");
                TextBox logoUrltextBox = (TextBox)e.Item.FindControl("logoURLTextBox");
                if (ddLinktype != null && logoUrltextBox !=null)
                {
                    ddLinktype.Attributes["onchange"] = "onLinkTypeChange(this,' ctl00_ContentPlaceHolder1_ListView1_"+logoUrltextBox.ClientID+"')";
                }
                if (ddLinktype.SelectedValue == "Text")
                {
                    if (logoUrltextBox != null)    logoUrltextBox.Style["display"] = "none";
                }
            }
        }
最终生成的HTML代码:
 <td>
                    <select name="ListView1$ctrl2$ddlLinkType" id="ListView1_ctrl2_ddlLinkType" onchange="onLinkTypeChange(this,'ctl00_ContentPlaceHolder1_ListView1_ctrl6_logoURLTextBox')">   //传递的参数
<option selected="selected" value="Text">文本</option>
<option value="Pic">图片</option>
</select>
                </td>
                <td>
                    <input name="ListView1$ctrl2$siteURLTextBox" type="text" id="ListView1_ctrl2_siteURLTextBox" /><span id="ListView1_ctrl2_RequiredFieldValidator3" style="color:Red;visibility:hidden;">*</span>
                </td>
                <td>
                    <input name="ListView1$ctrl2$logoURLTextBox" type="text" id="ctl00_ContentPlaceHolder1_ListView1_ctrl6_logoURLTextBox" style="display:none;" />      //HTML页面中的ID
                </td>
            </tr>
参考 .Net 4.0 Attributes.Add encoding bug :
1. 创建HtmlAttributeEncodingNot
public class HtmlAttributeEncodingNot : System.Web.Util.HttpEncoder { protected override void HtmlAttributeEncode(string value, System.IO.TextWriter output) { output.Write(value); } }
2. 在web.config中添加如下配置
<httpRuntime encoderType="HtmlAttributeEncodingNot"/>
试的时候有个问题,HtmlAttributeEncode是protected类型的,我在其他类中访问不了,还请指教!
@mingli: 不需要在其他类中访问
@dudu: 谢谢,明白啦,有用!!
用双引号 拼接字符串试试
学习了。
传之前用HttpUtility.HtmlEncode()方法进行处理一下,拿到后在HttpUtility.HtmlDecode()获取
请问拿到后怎么Decode啊,不太明白
后台代码获取后Decode后再放到HTML上,可以用JS
使用双引用加转义符试试,即
ddLinktype.Attributes["onchange"] = "onLinkTypeChange(this,\\\"ctl00_ContentPlaceHolder1_ListView1_"+logoUrltextBox.ClientID+\\\")";
小学生来看看!