最后原因找出来了。 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() }
<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
net是有viewstate的.
除非你手动清空了.
从以上代码来看,我没有手动清空。我也没搞懂,为什么给dropdownlist添加item后,textpono中的值会变成空白
4楼:
你是说用这一句来代替原有的textbox吗?可否写的详细点。
原本是:当点button时,执行function search(),进一步选择执行LotResult()如果改成txtPONO onchange="LotResult()"不存在txtpono内容会清空的问题。是哪里的原因造成的呢?
而在search()中最后一行return false。我在想是不是这个return造成textbox的内容被清空?因为我试了一下,将txtPONO的onchange调用的函数由LotResult()改成了search().结果也出现txtPONO的值被清空了。
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中比较是==,将所有=换成==就正常了。