将javascript数组转换为C#NameValueCollection

时间:2016-05-22 20:38:02

标签: javascript c# jquery asp.net

从aspx / jqGrid屏幕,我需要向服务器发送选择标准。 我有几个文本框 - 和一个输入按钮 -

float:left

但onClientClick似乎不起作用......

<asp:TextBox ID="kPID" runat="server" CssClass="tbBlock" Width="50px" />
           <asp:TextBox ID="kLN" runat="server" CssClass="tbBlock" />
           etc...
           <asp:Button ID="InputEnter_Button" runat="server"  
             OnClientClick="Client_InputEnterClick"   OnClick="InputEnter_Click" />

所以我扩展了serializeGridData -

<script type="text/javascript">
        function LookupGrid_Client_InputEnterClick() {
            var formValues = { kPID: $("#kPID").val(), kLN: $("#kLN").val(), kFN: $("#kFN").val(), 
                   kBD: $("#kBD").val(), kPhone: $("#kPhone").val(), kStreet: $("#kStreet").val() };
            $('#LookupGrid').setGridParam({ postData: formValues });
        }
    </script>

然后jqgrid使用了GET函数Async,现在我可以获取URL值 -

  <script type="text/javascript">
    $.extend($.jgrid.defaults, {
        serializeGridData: function(data) {
            var kkPID = document.getElementById($("[id$=_kPID]").attr("id")).value;
            var kkLN = document.getElementById($("[id$=_kLN]").attr("id")).value;
            etc...
            var formValues = { kPID: kkPID, kLN: kkLN, kFN: kkFN, kBD: kkBD, kPhone: kkPH, kStreet: kkST };
            return "{'PECLookupArgs':'" + JSON.stringify(formValues) + "'}"; 
        }
    });
</script>

哪个有3个键,最后一个是null(除了:为什么它是null?) -

<trirand:JQGrid ID="LookupGrid" runat="server" Height="300px" Width="50%" LoadOnce="true"
    OnDataRequesting="LookupGrid_DataRequesting"  >
and code behind ...
protected void LookupGrid_DataRequesting(object sender, Trirand.Web.UI.WebControls.JQGridDataRequestEventArgs e)
{
    NameValueCollection qscoll = HttpUtility.ParseQueryString(Request.QueryString.ToString());

我试过这么简单的方法 -

?qscoll[null]
"{'PECLookupArgs':'{\"kPID\":\"\",\"kLN\":\"\",\"kFN\":\"\",\"kBD\":\"\",\"kPhone\":\"\",\"kStreet\":\"\"}'}"

但是\&#34;还在那里......那里必须有更好的方法。好吗?

0 个答案:

没有答案