Management attributes are rendered in dot net 4 encoding - how to disable encoding?

I have a problem with asp.net 4.

When I add an attribute on the controls, then its encoding is rendered.

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';
}";

I get rendering

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

And every hash ' changed to & # 39;

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

My unsuccessful attempt

Everything is ready for me, some think, but I fail. For example, this fails.

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

I also find that these attributes are displayed and are on

public virtual void RenderBeginTag (HtmlTextWriterTag tagKey) ,

, , , .

asp net , EncodeType - , - , , , , .

, .

, Microsoft .

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- , script, onfocus JavaScript. jQuery , , .

, , , , , - MS.

+3
4

MSDN WebControl.Attributes ...

script WebControl, . script, ClientScript .

, , .

, client script , .

javascript , , script .

+1
+2

MvcHtmlHelper .

| ~ | ', ' , Html.TextBox , .

.

+1

, AddAttributesToRender. , , .

, , . , :

public class MyCustomButton : Button
{
    protected override void AddAttributesToRender(HtmlTextWriter writer)
    {
        base.AddAttributesToRender(writer);
        writer.AddAttribute("onclick", "myJavascriptFunction('a string');", false); // passing false to the AddAttribute method tells it not to encode this attribute.
    }
}

, onclick , onclick. , .

0

Source: https://habr.com/ru/post/1747175/


All Articles