0

I am using an inline jquery in the c# code and it works. But when I try to call it through js file, it does not work.

C# code

tableCell.Attributes.Add("onclick", 
                         @" if($(""div[id*='Name'] input[id*='" +
                         checkboxID + @"']"").is(':checked')" );

Here, I get the value true. So Now I try to make a function in js file and call it.

tableCell.Attributes.Add("onclick",
                         "javascript:Foo(this,'" + checkBoxID + "');
                         return false;");

Js File :

function ToggleScorecardConfig(sender,checkboxID) {
    var a = checkboxID + "@";
    alert(a); //WORKS
    alert($(""div[id*='Name'] input[id*='" + checkBoxID +
              @"']"").is(':checked')); //ERROR : ')' Expected
}

I know I am doing some very small mistake, Can anyone please guide me.

0

1 Answer 1

1

You have double double quotes in the JS file code, should just be:

$("div[id*='Name'] input[id*='" + checkBoxID + "']") 

The '@' is used to escape the double quotes in C#, that's why the in-line code works, you don't need that in JS

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

5 Comments

It says '@' Invalid. double double quotes work in inline query.
This gives me false, but I should get true, as in Inline query, I get true value.
What do you get when if you do alert($("div[id*='Name'] input[id*='" + checkBoxID + "']").length)
In the inline query, I get some length as 2,4,11 but when I try with JS File, I get 0 only.
You checked that checkBoxID has the right value? You can also debug the jQuery result and review the selector.

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.