-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.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
TheSchnitz
  • 31
  • 1
  • 11

1 Answers1

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 + "'} )"
            );
Sky Fang
  • 1,101
  • 6
  • 6
  • 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? – TheSchnitz Jul 20 '15 at 22:20
  • Note that there is no reason to use array as list of parameter (because it is already array on JavaScript side)... [Options pattern](http://stackoverflow.com/questions/9602449/a-javascript-design-pattern-for-options-with-default-values) is nicer, but still need proper encoding of parameters (which depend on framework used to render pages and hence not answerable in current state) – Alexei Levenkov Jul 20 '15 at 23:03