C# 在js中获取控件的值
C# 中控件的代码
机种:<asp:DropDownList ID="ddl_Type" AutoPostBack="true" runat="server" Height="19px" Width="128px"> <asp:ListItem Value="机种1">机种1</asp:ListItem>
JS中取值方法
let rate = document.getElementById("ddl_Type").value;
把值传入到.ashx页面并在.ashx页面取值
$(document).ready(function () { $('#myButton').click(function () { var chartWidth = '45%'; // 设定图表宽度 var chartHeight = '300px'; // 设定图表高度 let dpDept = document.getElementById("dpDept").value; let ddl_Type = document.getElementById("ddl_Type").value; let ddl_Processes = document.getElementById("ddl_Processes").value; let ddl_Items = document.getElementById("ddl_Items").value; $.ajax({ type: "POST", url: "GetEchartsMachineFirstData.ashx?dpDept=" + dpDept + "&ddl_Type=" + ddl_Type + "&ddl_Processes=" + ddl_Processes + "&ddl_Items=" + ddl_Items + "", contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { }, error: function (xhr, status, error) { console.error("AJAX request failed:", status, error); console.log(xhr.responseText); // 打印服务器返回的错误信息 } }); }); });
取值页面(.ashx页面)
string dpDept = context.Request.Params["dpDept"]; string ddl_Type = context.Request.Params["ddl_Type"]; string ddl_Processes = context.Request.Params["ddl_Processes"]; string ddl_Items = context.Request.Params["ddl_Items"];