ASP.NET quote character encoding causes problems when setting a control's property

后端 未结 2 1024
余生分开走
余生分开走 2021-01-22 03:00

I have an ASP.NET web application and at a certain point I do this:

mycontrol.stringparameterforjscript = \"document.getElementById(\'\" + myotherparam + \"\').v         


        
2条回答
  •  遥遥无期
    2021-01-22 03:46

    I think you might need the @ on both string literals in your assignment, and remove the slashes:

    mycontrol.stringparameterforjscript = @"document.getElementById('" + myotherparam + @"').value = 'Hello'";
    

    EDIT

    How I did it:

    On the .aspx:

    
    

    In the code:

    protected void Page_Load(object sender, EventArgs e)
    {
        string myotherparam = "paramval";
        tbTest.Attributes.Add("onfocus", @"document.getElementById('" + myotherparam + @"').value = 'Hello'");
    }
    

    Resultant output:

    
    

提交回复
热议问题