user3319384
user3319384

Reputation: 33

To pass parameter from server side to client side

In the below code I have a dropdown in this I call js function from server side and I want to pass parameter to js function. In my case parameter is not passing. Please help me to solve this issue.

codebehind:

 Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "<script type=text/javascript> AddItem(" + EnumRows + ");</script>", true);

js:

function AddItem(EnumRows) {    
    // Create an Option object                
    // var opt = document.createElement("option");
    alert('this');
    // Add an Option object to Drop Down/List Box
    document.getElementById("<%=cbField.ClientID%>").options.add(opt);
    // Assign text and value to Option object
    opt.text = Value;
}

Upvotes: 0

Views: 1603

Answers (3)

Ilie NEACSU
Ilie NEACSU

Reputation: 540

Try to use escape_javascript method on your parameter.

<%= escape_javascript(your_parameter) %>

Upvotes: 0

Pragnesh Khalas
Pragnesh Khalas

Reputation: 2898

Below will help you

Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "AddItem(" + EnumRows + ");", true);

Upvotes: 0

Sachin
Sachin

Reputation: 40970

Try this

Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "AddItem('" + EnumRows + "');", true);

Upvotes: 1

Related Questions