控制属性上呈现点网4恩codeD - 如何禁用编码? [英] Control Attributes render Encoded on dot net 4 - how to disable the encoding?

查看:115
本文介绍了控制属性上呈现点网4恩codeD - 如何禁用编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,在asp.net中4。

I have an issue in asp.net 4.

当我上的控件添加属性,那么使之恩codeD。

例如,当我键入此code

For example, when I type this code

txtQuestion.Attributes["onfocus"] = 
    "if(this.value == this.title)
{
   this.value = '';
   this.style.backgroundColor='#FEFDE0';
   this.style.color='#000000';
}";

我得到渲染

onfocus="if(this.value == this.title){this.value = 
'';this.style.backgroundColor='#FEFDE0';
this.style.color='#000000';}"

和每 散了变化的&安培; #39;

有没有一种方法来禁用这个新的未来只能在某些控件?或简单的方法来创建一个自定义呈现?

Is there a way to disable this new future only on some controls ? or an easy way to make a custom render ?

我都准备好了尝试一些认为,但我失败。
例如,这将失败。

I have all ready try some thinks but I fail. For example this fails.

txtQuestion.RenderingCompatibility = new Version("3.5");

我也找到了点,这个属性呈现,并且是

I also locate the point that this attributes renders and is on

公共虚拟无效RenderBeginTag(HtmlTextWriterTag中tagKey)功能,

有每个属性都有一个标志,如果他想成为EN $ C $的CD,但我不知道如何任何人都可以将其设置与否。

there every attribute have a flag if he wish to be encoded, but I do not know how can anyone set it or not.

在同样的问题在ASP网论坛,有一个解决方案这改变全球恩codeTYPE - 这是不是我搜索的解决方案 - 即给予解决和人说的这是不是一个伟大的解决办法,与潜在的安全问题或其他渲染的问题。

In the asp net forum in the same question, there is a solution that change the global EncodeType - this is not the solution that I search for - and the person that give the solution say that this is not a great workaround, with potential security issues or other render issues.

感谢您的所有先进的。

到现在为止Kervin发现,微软建议改用此命令。

Until now Kervin found that Microsoft suggest instead use this command.

txtQuestion.Attributes["onfocus"] = 
    "if(this.value == this.title){this.value = '';this.style.backgroundColor='#FEFDE0';this.style.color='#000000';}";

使用这一个。

    Page.ClientScript.RegisterExpandoAttribute(txtQuestion.ClientID, "onfocus", 
 "if(this.value == this.title){this.value = '';this.style.backgroundColor='#FEFDE0';this.style.color='#000000';}");

和什么MS渲染,是在页面的结束,即使用JavaScript 在此控件添加的onfocus的脚本。
我们可以做到这一点,即使我们使用jQuery的自我和可能会更兼容。

And what MS render, is on the end of the page, a script that add onfocus on this control using JavaScript. We can do that even by our self with jQuery and probably be more compatible.

这是一个解决方案,但还是我想知道是否有一种方法,只是避免了属性编码,让我做什么,我希望我的方式 - 不是MS方法

This is a solution, but still I am wish to know if there is a way to just avoid the Attribute Encoding and let me do what I wish my way - not MS way.

推荐答案

从MSDN的 WebControl.Attributes物业文档...

From MSDN WebControl.Attributes Property Documentation...

注意

您不能客户端脚本添加到使用属性集合WebControl的实例。要添加客户端脚本,请使用页面控制ClientScript属性。

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.

问题是,的属性的预计数据,如果它在被设定的code-落后。

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.

如果您的JavaScript是静态的,那么事情会更简单,因为你可以向他们发送的脚本的控件注册很久以前的标签。

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.

这篇关于控制属性上呈现点网4恩codeD - 如何禁用编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆