是在用.net ajax吧?那你的textbox是不是没有启用viewstate?还有其他一些情况,最好附上代码

解决方案 »

  1.   

    我并没有设置过viewstate=false,因为刚刚开始学,所以也不太懂。恳请指点。以下是三个控件的HTML代码   <asp:TextBox ID="TxtPONO" runat="server"></asp:TextBox>
       <asp:DropDownList ID="DropDLLot" runat="server" Height="16px" Width="126px" 
            Enabled="False" >
    <asp:Button ID="BtnSearch" runat="server" Text="Search"  OnClientClick="return Search()" />
    以一旧javascript中的部分代码:function Search()
    {
        if (document.getElementById("txtPONO").value = "") {
           document.write ("Please type the PO NO to search!")
           }
        else if (document.getElementById("DropDLLot").disabled = true)  {
            LotResult()
            }
        else if (document.getElementById("DropDLShade").disabled = true) {
           ShadeResult()
           }
        else if (document.getElementById("DropDLLocation1").disabled = true) {
           Loc1Result()
           }
        else if (document.getElementById("DropDLLocation2").disabled = true) {
            Loc2Result()
            }
        else {
            DatagridResult()
            }
            
            return false 
    }
    function LotResult() 

        var PONO=document.getElementById("txtPONO");
        var POvalue = PONO.value; 
        AjaxTransfer.GetLotList(PONO.value,get_Lot_Result_CallBack);
        document.getElementById("DropDLLot").disabled = false;
        document.getElementById("DropDLShade").disabled = true;
        document.getElementById("DropDLLocation1").disabled = true;
        document.getElementById("DropDLLocation2").disabled = true;
        PONO.value = POvalue;
    }function get_Lot_Result_CallBack(response)
    {
        if (response.value != null)
        {
        document.all("DropDLLot").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].Lot;
        document.all("DropDLLot").options.add(new Option(name));
        }
        }
        }
    return
    }
    以下是部分的vb.net代码:Namespace AjaxERP
        Public Class AjaxTransfer
            <Ajax.AjaxMethod()> _
            Public Function GetLotList(ByVal PONO As String) As DataSet
                Return GetDataSet(PONO, "PONO", "", "", "", "")
            End Function        <Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)> _
            Public Function GetShadeList(ByVal PONO As String, ByVal Lot As String) As DataSet            Return GetDataSet(PONO, "LOT", Lot, "", "", "")
            End Function
      

  2.   

    不会清空的,
    net是有viewstate的.
    除非你手动清空了.
      

  3.   

    用<input type="hidden" name="" value=""> 
      

  4.   

    3楼:
    从以上代码来看,我没有手动清空。我也没搞懂,为什么给dropdownlist添加item后,textpono中的值会变成空白
    4楼:
    你是说用这一句来代替原有的textbox吗?可否写的详细点。
      

  5.   

    有一个要提一下,如果我将javascript换个事件来触发,结果不一样:
    原本是:当点button时,执行function search(),进一步选择执行LotResult()如果改成txtPONO onchange="LotResult()"不存在txtpono内容会清空的问题。是哪里的原因造成的呢?
      

  6.   

    我觀查了一下“返回”這個按鈕。如果頁面刷新後,該按鈕應該爲可用狀態,沒有刷新應該就是灰色。通過button的onclientclick與textbox的onchange執行後,都是灰色。但爲什麽button的onclientclick會出現textbox內容被清空呢?
      

  7.   

    不知道各位有没有看到我在button的onclientclick事件中是return search()
    而在search()中最后一行return false。我在想是不是这个return造成textbox的内容被清空?因为我试了一下,将txtPONO的onchange调用的函数由LotResult()改成了search().结果也出现txtPONO的值被清空了。
      

  8.   

    最后原因找出来了。
    function Search()
    {
        if (document.getElementById("txtPONO").value = "") {
           document.write ("Please type the PO NO to search!")
           }
        else if (document.getElementById("DropDLLot").disabled = true)  {
            LotResult()
            }
        else if (document.getElementById("DropDLShade").disabled = true) {
           ShadeResult()
           }
        else if (document.getElementById("DropDLLocation1").disabled = true) {
           Loc1Result()
           }
        else if (document.getElementById("DropDLLocation2").disabled = true) {
            Loc2Result()
            }
        else {
            DatagridResult()
            }
            
            return false 
    }
    里面的判断都用了“=”,实际上这是赋值,在javascript中比较是==,将所有=换成==就正常了。