0

I was wondering if there are any c# libraries that will readily format a string to be used in a onclick html attribute property.

I am using c# to dynamically generate an html page and am dynamically generating the javascript for some onclick events. I want to make sure characters such as &"\ ... etc does not cause the html to break or be ignored. For example in the following example of I wanted to display the alert message h\&#3m, I wouldn't be able to do so unless I created separate logic to handle the \ and &:

function method1(inputValue){
  alert(inputValue);
  }
<input type="button" value="button1" onclick="method1('h\&#3m')"/>

1 Answer 1

1

You would want to check out the HtmlEncode method of HttpServerUtility. https://msdn.microsoft.com/en-us/library/w3te6wfz(v=vs.110).aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.