Friday, 23 October 2015

Pass function Parameter & string value in string builder function.

Recently I was working with dynamic controls where I got in to a small issue where I need to provide parameters in JavaScript function. I tried lots of things , But here is the approach which solved my issue:

Example:

sb.AppendLine(@"<li><a href='#' onclick='FunctionTest(" + "\"" + string1 + "\" ,\"" + string2+ "\"," + int1 + ")'>" + string4 + "</a></li>");

Explanation:

We can divide above code in following parts:

1) sb.AppendLine(@"<li><a href='#' onclick='FunctionTest(" completes first string
2) + "\"" + string1 + "\" Adds " string1 " (string parameter) to function
3) " + int1 + " Adds int1 (integer parameter) to function
4) )'>" + string4 + "</a></li>"); Complete remaining string

No comments:

Post a comment