0

Essentially what I'm trying to do is fairly simple....pass more than one parameter (4 total eventually) into a javascript function from my ASP.NET code behind.

What I've tried to do is this in the ASCX file...

function ToggleReportOptions(filenameText, buttonText) { /*stuff happens here*/ }

and this in the ASCX.cs file...

string testing123 = "testStringOne";
string testing124 = "testStringTwo";
optReportOptionsRunRealTime.Attributes["onClick"] = "ToggleReportOptions('" + testing123 + ", " + testing124 + "')";
optReportOptionsOffline.Attributes["onClick"] = "ToggleReportOptions('" + testing123 + ", " + testing124 + "')";

but this doesn't seem to work as in my output the first variable contains "testStringOne, testStringTwo" and the 2nd variable is "undefined"

Any help on clearing up my probably stupid issue here would be great (i'm very inexperienced with javascript, more of a .NET developer)

1 Answer 1

4

You've missed out a few single-quotes, meaning that you're passing a single string containing a comma rather than two separate strings. That is, you're passing 'testStringOne, testStringTwo' rather than 'testStringOne' and 'testStringTwo'.

Try this instead:

optReportOptionsRunRealTime.Attributes["onClick"] =
    "ToggleReportOptions('" + testing123 + "', '" + testing124 + "')";
optReportOptionsOffline.Attributes["onClick"] =
    "ToggleReportOptions('" + testing123 + "', '" + testing124 + "')";
Sign up to request clarification or add additional context in comments.

1 Comment

that seems to have worked, found a new little error, but the single quotes fixed the issue of the parameters sticking to each other thanks!!

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.