Reputation: 33
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
Reputation: 540
Try to use escape_javascript method on your parameter.
<%= escape_javascript(your_parameter) %>
Upvotes: 0
Reputation: 2898
Below will help you
Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "AddItem(" + EnumRows + ");", true);
Upvotes: 0
Reputation: 40970
Try this
Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", "AddItem('" + EnumRows + "');", true);
Upvotes: 1