用AJAX级联处理部门关系,但在用BUTTON取值的时候出现如下问题...
回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。 将所有代码贴出,请高手解决:
<body style="background-color: #8198FA;">
    <form id="form1" runat="server">
        <div>
            <br />
            <div style="text-align: center">
                <div class="container" style="width: 950px; height: 590px; padding: 0px;">
                    <div class="c" style="height: 590px; background: #555; border: 1px solid #ccc; padding: 16px;">
                        <table style="width: 400px">
                            <tr>
                                <td colspan="2">
                                    <div style="font-weight: bold; font-size: 13px; text-align: center">
                                        添加固定资产</div>
                                </td>
                            </tr>
                                                        <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    编号</td>
                                <td>
                                    <span style="font-size: 8pt; color: #66ccff">系统自行添加</span></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    资产类型</td>
                                <td>
                                    <span style="font-size: 8pt; color: #66ccff">
                                        <asp:DropDownList ID="leixinglist" runat="server">
                                        </asp:DropDownList><a href="addlx.aspx">添加</a></span></td>
                            </tr>                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    资产型号</td>
                                <td>
                                    <span style="font-size: 8pt; color: #66ccff"><asp:DropDownList ID="xinghaolist"
                                        runat="server">
                                    </asp:DropDownList><a href="addxh.aspx">添加</a></span></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    序列号</td>
                                <td>
                                    <asp:TextBox ID="TextBox3" runat="server" Width="279px"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    详细配置</td>
                                <td>
                                    <asp:TextBox ID="TextBox4" runat="server" Style="overflow-y: visible" Height="50px"
                                        TextMode="MultiLine" Width="279px"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; height: 31px; text-decoration: none;">
                                    有线MAC</td>
                                <td style="height: 31px">
                                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    有线IP</td>
                                <td>
                                    <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    无线MAC</td>
                                <td>
                                    <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    无线IP</td>
                                <td>
                                    <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    所在部门</td>
                                <td>
                                    <asp:DropDownList ID="deptlist" runat="server">
                                    </asp:DropDownList></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    使用人</td>
                                <td>
                                    <asp:DropDownList ID="peoplelist" runat="server">
                                    </asp:DropDownList></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    价格</td>
                                <td>
                                    <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    购买时间</td>
                                <td>
                                    <asp:TextBox ID="TextBox9" runat="server" onFocus="calendar()"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none;">
                                    过保时间</td>
                                <td>
                                    <asp:TextBox ID="TextBox10" runat="server" onFocus="calendar()"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td style="width: 94px; font-size: 12px; text-decoration: none; height: 31px;">
                                    物品名称</td>
                                <td style="height: 31px">
                                    <asp:TextBox ID="TextBox11" runat="server"></asp:TextBox></td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <div style="font-size: 12px; text-align: center; text-decoration: none">
                                        <asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" ImageUrl="~/images/add.gif" />
                                        &nbsp; &nbsp; &nbsp; &nbsp;
                                        <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/images/quxiao.gif" /></div>
                                </td>
                            </tr>
                        </table>
                        &nbsp;
                    </div>
                </div>
            </div>
        </div>
    </form>
</body>

解决方案 »

  1.   


    C#:using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using zyp.SQLServerDAL;public partial class addzichan : System.Web.UI.Page
    {    protected void Page_Load(object sender, EventArgs e)
        {
            Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethod));
            if (!IsPostBack)
            {
                this.leixinglist.DataSource = AjaxMethod.GetLeixingList();
                this.leixinglist.DataTextField = "leixing";
                this.leixinglist.DataValueField = "lx_id";
                this.leixinglist.DataBind();            this.leixinglist.Attributes.Add("onclick", "xinghaoResult();");            this.deptlist.DataSource = AjaxMethod.GetDeptList();
                this.deptlist.DataTextField = "dept";
                this.deptlist.DataValueField = "did";
                this.deptlist.DataBind();            this.deptlist.Attributes.Add("onclick", "PeopleResult();");        }
        }
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string lx = "select lx_id from p_leixing where leixing='" + this.leixinglist.Text.Trim() + "'";
            string xh = "select xh_id from p_xinghao where xinghao='" + this.xinghaolist.Text.Trim() + "'";
            string dept = "select did from Dept where dept='" + this.deptlist.Text.Trim() + "'";
            string people = "select uid from worker where worker='" + this.peoplelist.Text.Trim() + "'";
            string sql = "insert into p_zichan (leixing,xinghao,xuliehao,peizhi,yxMAC,yxIP,wxMAC,wxIP,dept,people,jiage,goumaisj,guobaosj,zcname)values('" + Convert.ToInt32(DbHelperSQL.GetSingle(lx)) + "','" + Convert.ToInt32(DbHelperSQL.GetSingle(xh)) + "','" + this.TextBox3.Text.Trim() + "','" + this.TextBox4.Text.Trim() + "','" + this.TextBox1.Text.Trim() + "','" + this.TextBox5.Text.Trim() + "','" + this.TextBox6.Text.Trim() + "','" + this.TextBox7.Text.Trim() + "','" + Convert.ToInt32(DbHelperSQL.GetSingle(dept)) + "','" + Convert.ToInt32(DbHelperSQL.GetSingle(people)) + "','" + this.TextBox8.Text.Trim() + "','" + this.TextBox9.Text.Trim() + "','" + this.TextBox10.Text.Trim() + "','" + this.TextBox11.Text.Trim() + "')";
            DbHelperSQL.ExecuteSql(sql);
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language='Javascript'>alert('添加成功!')</script>");
            return;
        }}附上级联JS:
       //人员------------------------------
    function PeopleResult() 

    var worker=document.getElementById("deptlist");
    AjaxMethod.GetPeopleList(worker.value,get_worker_Result_CallBack);
    }

    function get_worker_Result_CallBack(response)
    {
    if (response.value != null)
    {
    //debugger;
    document.all("peoplelist").length=0;    
         var ds = response.value;
    if(ds != null && typeof(ds) == "object" && ds.Tables != null)
    {
    for(var i=0; i<ds.Tables[0].Rows.length; i++)
         {
         var name=ds.Tables[0].Rows[i].worker;
           var id=ds.Tables[0].Rows[i].father;
           document.all("peoplelist").options.add(new Option(name,id));
         }
    }
    }
    return
    }
    //型号---------------------------------
    function xinghaoResult()
    {
      var xinghao=document.getElementById("leixinglist");
    AjaxMethod.GetXinghaoList(xinghao.value,get_xinghao_Result_CallBack);
    }

    function get_xinghao_Result_CallBack(response)
    {
    if (response.value != null)
    {
    //debugger;
    document.all("xinghaolist").length=0;    
         var ds = response.value;
    if(ds != null && typeof(ds) == "object" && ds.Tables != null)
    {
    for(var i=0; i<ds.Tables[0].Rows.length; i++)
         {
         var name=ds.Tables[0].Rows[i].xinghao;
           var id=ds.Tables[0].Rows[i].father;
           document.all("xinghaolist").options.add(new Option(name,id));
         }
    }
    }
    return
    }
    请高手解决 谢谢!!!
      

  2.   

    最好在js里用alert()看看是否能得到值!!
      

  3.   

    js里面是肯定没问题的..
    数值取到了.
    但是没法在提交的时候从界面再提到后台..也就是说后台无法取到前台所select的数据.
    听说有一种方法把值赋给hiddenfield.
     然后再从后台读取hiddenfield的值..
    不知道这种方法要怎么做?
    谁知道怎么处理上面的问题.请告诉我答案 谢谢!
      

  4.   

    C#定义一个类(包含输入的所有字段),然后用ajax的方法把类返回到前台给js处理,处理好以后再把这个类返回到后台,这类你要的东西就能取到了如
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Regex_Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
        <title>HTML with XML Data Island</title>
        <script defer="defer">
        function setclass()
        {
        var c1=Regex_Default.GetClass().value;
        c1.InputStr = "1";
        c1.PatternStr = "2";
        c1.ReplaceStr = "3";
        var c2=Regex_Default.OutClass(c1).value;
        alert(c2.ContentStr+c2.CodeStr);
        }
        
        </script>
    </head>
    <body>
    <form id="Form1" runat="server">
    <input type="button" value="dd" onclick="setclass()" /></form>
    </body>
    </html>using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using AjaxPro;
    public partial class Regex_Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(Regex_Default));
        }
        [AjaxMethod]
        public InputClass GetClass()
        {
            InputClass c = new InputClass();
            return c;
        }
        [AjaxMethod]
        public OutClass OutClass(InputClass c1)
        {
            OutClass c2 = new OutClass();
            c2.ContentStr = c1.InputStr;
            c2.CodeStr = c1.PatternStr;
            return c2;    
        }
    }
    using System;
    /// <summary>
    /// ajax的输入类
    /// </summary>
    public class InputClass
    {
        private string inputstr;
        private string patternstr;
        private string replacestr;
        private bool isignorecase;
        private bool ismultiline;
        private bool issingleline;
        private bool isrighttoleft;
        private int index;
        public string InputStr
        {
            set { inputstr = value; }
            get { return inputstr; }
        }
        public string PatternStr
        {
            set { patternstr = value; }
            get { return patternstr; }
        }
        public string ReplaceStr
        {
            set { replacestr = value; }
            get { return replacestr; }
        }
        public int Index
        {
            set { index = value; }
            get { return index; }
        }
        public bool IsIgnoreCase
        {
            set { isignorecase = value; }
            get { return isignorecase; }
        }
        public bool IsMultiline
        {
            set { ismultiline = value; }
            get { return ismultiline; }
        }
        public bool IsSingleline
        {
            set { issingleline = value; }
            get { return issingleline; }
        }
        public bool IsRightToLeft
        {
            set { isrighttoleft = value; }
            get { return isrighttoleft; }
        }
    }using System;
    /// <summary>
    /// ajax的输出类
    /// </summary>
    public class OutClass
    {
        private string content;
        private string code;
        private int index;
        private int sp;
        private int ep;
        public string ContentStr
        {
            set { content = value; }
            get { return content; }
        }
        public string CodeStr
        {
            set { code = value; }
            get { return code; }
        }
        public int Index
        {
            set { index = value; }
            get { return index; }
        }
        public int SP
        {
            set { sp = value; }
            get { return sp; }
        }
        public int EP
        {
            set { ep = value; }
            get { return ep; }
        }
    }
      

  5.   

    你说的是不是Input(hidden)html控件啊!!
    把选择的值放在Input中,然后更具input值更新!!
      

  6.   

    能做个示范么 谢谢..
    dropdownlist里面取值放到hidden中
      

  7.   

    AJAX级联,谁能不能跟我说一下思路?
      

  8.   

    你的值里,是不是带了html标签或者< > 这样的符号,要在WEB.CONFIG里设置一下.AJAX级联,就跟你做服务器端程序一样的思路,只不过是异步调用获取数据罢了.
      

  9.   

    http://www.cnblogs.com/chen79/archive/2007/12/09/988509.html
    级联示例
      

  10.   

    你可以在后台给dropdownlist赋值,使其得到保存
    例如:dropdownlist1.SelectedValue = Request.Form["dropdownlist1"];
      

  11.   

    问题解决了..
    因为客户端用的是JS显示数据.
    所以要用JS获取所选值..
    再将值放入隐藏域 hidden..
    后台从隐藏域中读取值...
    随便散分了...谢谢各位!
      

  12.   

    onselectchanged='document.all.hiddent1.value=取当前值'
    将hiddent1设为服务器控件,在后台取值就行了