我在代码里写
this.Button1.Attributes.Add("onclick", "javascript:alert('abc')");生成的HTML变成
<input type="submit" name="ctl00$ContentPlaceHolder1$Button1" value="Button" onclick="javascript:alert(&#39;abc&#39;);" id="ContentPlaceHolder1_Button1" />
我希望的结果是:
<input type="submit" name="ctl00$ContentPlaceHolder1$Button1" value="Button" onclick="javascript:alert('abc');" id="ContentPlaceHolder1_Button1" />请问需要怎么做?

解决方案 »

  1.   

    很明显被htmlencode了,用htmldecode解码
      

  2.   

    被自动编码了,你可以直接利用前台JS来实现,而没必要去在CS里面纠结这个问题,而且这样也不影响效果
      

  3.   

    因为JS执行时.'abc'是以字符串进行处理.&#39;abc&#39;根本处理不了. 
      

  4.   

    而且.在VS2005里和VS2008里试了都能在HTML显示成'abc',只有在2010里才有这种情况.
      

  5.   


      好像2010 会把单引号编码掉
      --try
      --this.Button1.Attributes.Add("onclick", "javascript:alert('abc')");
      this.Button1.Attributes["onclick"] = "alert('abc');";
      

  6.   


    注释当sql使了  
    应该是IE 有这个问题 FF和GG 显示的正确  
      

  7.   

    写在前台OnClientClick也是一样.不信你去试试在VS2010里.
      

  8.   

    楼主,我用的是2010测试的,没有出现你的问题
    代码如下://html中
     <input type ="submit" value="提交" id="button" runat="server" />//cs中
    protected void Page_Load(object sender, EventArgs e)
    {
        this.button.Attributes.Add("onclick", "javascript:alert('abc')");
    }