jQuery的序列化和.NET控件 [英] jquery serialize and .net controls

查看:164
本文介绍了jQuery的序列化和.NET控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery序列化()与asp.net服务器控件。

i use jquery serialize() with asp.net server controls.

        <asp:DropDownList ID="ddFirmaAd" runat="server" Width="180" Height="25">
        </asp:DropDownList>

当我打印数组

ajaxRequest("AjaxServices/Insert.aspx", $("#aspnetForm").serialize(), $('#returnMessage'), 0, $(this)); 

 function ajaxRequest(pageURL, queryString, putArea, timeout, disabledCtrl) {
        if (disabledCtrl != null)
            disabledCtrl.attr("disabled", "true");
        $.ajax({
            async: true,
            timeout: timeout,
            cache: false,
            url: pageURL + "?" + queryString,  


alert($("#aspnetForm").find("input,textarea,select,hidden").not("#__VIEWSTATE,#__EVENTVALIDATION").serialize());

它打印ddFirmaAd客户端名称的窗口=CT100%24ct100%24ContentPlaceHolder1%24ContentPlaceHolder1%24ddFirmaAd = 2

it prints ddFirmaAd client name on window ="ct100%24ct100%24ContentPlaceHolder1%24ContentPlaceHolder1%24ddFirmaAd = 2 "

我想ddFirmaAd.selectedValue在code后面

i want to get ddFirmaAd.selectedValue on code behind

string value = request.queryString("ddFirmaAd");

但控件名称= CT100%24ct100%24ContentPlaceHolder1%24ContentPlaceHolder1%24ddFirmaAd

but the control name = ct100%24ct100%24ContentPlaceHolder1%24ContentPlaceHolder1%24ddFirmaAd

如何我使用序列化()和.NET控件?

how to i use serialize() and .net controls ?

推荐答案

如何字符串值=的Request.QueryString(ddFirmaAd.ClientID);

但如果你将这些值到不同的页面,您可以破解它是这样的:

but if you pass these values to a different page you can hack it like this:

字符串值= GetValueById(ddFirmaAd);

private string GetValueById(string endsWith)
    {
        var qs = HttpContext.Current.Request.QueryString;
        foreach(var key in qs)
        {
            string skey = key.ToString();
            if(skey.EndsWith(endsWith))
            {
                return qs[skey];
            }

        }
        return string.Empty;
    }

并不是说这是正确的。根本就没有拿出更好的东西基于当前提供的问题说明。

Not saying that it's correct. Simply cannot come up with anything better based on the currently provided problem description.

您可以配置的ClientIDMode 静态但保持唯一的ID变成您的责任,并可能导致很难找到客户端的错误。

You can configure ClientIDMode to static but then maintaining unique IDs becomes your responsibility and might lead to hard to find client side bugs.

这篇关于jQuery的序列化和.NET控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆