-1

For instance Is it possible to pass the following parameters as arguments to a JS function from code-behind?:

ddlLines.Attributes.Add("onchange", "setPanel("
        + " '" + ddlAdd.ClientID + "', "
        + " '" + nCkPTitle.ClientID + "', "
        + " '" + manCkEntry.ClientID + "', "
        + " '" + nCkLabel.ClientID + "', "
        + " '" + txtRefNo.ClientID + "', "
        + " '" + TCEE.pval + "', "
        + " '" + TCEE.ptxt + "', "
        + " '" + ddlLines.ClientID + "' "
        + ");"

At this time my JS function argument list is as follows:

function setPanel(ddlClientId, lblClientId, lblManCLientId, 
    lblRefNo, altRefNo, altValParm, altTxtParm, ddlLinesClientId){
   ...
}

I would like to be able to dynamically send an indeterminate list of parameters as arguments to the JS function from the code behind.

I have researched the .apply() function, but have not been able to use it successfully.

1 Answer 1

0

You just need to add [] ,it is means Array in js

ddlLines.Attributes.Add("onchange", "setPanel("
        + " ['" + ddlAdd.ClientID + "', "
        + " '" + nCkPTitle.ClientID + "', "
        + " '" + manCkEntry.ClientID + "', "
        + " '" + nCkLabel.ClientID + "', "
        + " '" + txtRefNo.ClientID + "', "
        + " '" + TCEE.pval + "', "
        + " '" + TCEE.ptxt + "', "
        + " '" + ddlLines.ClientID + "'] )"
        );

But I suggest that you can use json here,such as

ddlLines.Attributes.Add("onchange", "setPanel("
            + " {'aaaID':'" + ddlAdd.ClientID + "', "
            //...
            + " 'zzzID':'" + ddlLines.ClientID + "'} )"
            );
Sign up to request clarification or add additional context in comments.

2 Comments

Ah okay, I am new to programming, but I have used .ajax() JSON successfully to send a parameter list from JS to C# code-behind. looks like this is similar. I am assuming I would then use the KVP values in my JS function , correct?
Note that there is no reason to use array as list of parameter (because it is already array on JavaScript side)... Options pattern is nicer, but still need proper encoding of parameters (which depend on framework used to render pages and hence not answerable in current state)

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.