Control Attributes render Encoded on dot net 4 - how to disable the encoding?

后端 未结 4 2105
深忆病人
深忆病人 2021-01-20 03:55

I have an issue in asp.net 4.

When I add an attribute on controls, then the render it encoded.

For example, when I type this code

         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-20 04:13

    From MSDN WebControl.Attributes Property Documentation...

    Note

    You cannot add client-side script to a WebControl instance using the Attributes collection. To add client-side script, use the ClientScript property on the Page control.

    The problem is that Attributes expects data if it's being set in the code-behind.

    The solution is to send back a client script with your client side handler functions then you may set the attribute with the name of your functions.

    If your javascript is static, then things are even simpler, since you can send them in a script tag long before the controls are registered.

提交回复
热议问题