简体   繁体   中英

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;
}

尝试这个

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

以下将帮助您

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

尝试在参数上使用escape_javascript方法。

<%= escape_javascript(your_parameter) %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM