Hi Steve,
So does Bruce's suggestion on checking the "autopostback" property work?
By
default DropDownlist's AutoPostBack is set to false so that changing it's
selectedItem at clientside won't cause post back. Anyway, here is a
simple
test page I've made which contains code using both clientside script and
serverside code to achieve the result you required, you may have a test on
your side to see whether it works:
==========aspx=============
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="
http://schemas.microsoft.com/intellisense/ie5">
<script language="jscript">
function lstClient_change(lst)
{
var txt = document.getElementById("txtClient");
var selVal = lst.options[lst.selectedIndex].value;
if(selVal.toLowerCase() == "others")
{
txt.style.display = "";
txt.value = "Please input other values";
}else
{
txt.style.display ="none";
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="600">
<tr>
<td>Using Client Script:<br>
<asp

ropDownList id="lstClient" runat="server"></asp

ropDownList>
<asp:TextBox id="txtClient" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Using Server Code:<br>
<asp

ropDownList id="lstServer" runat="server"
AutoPostBack="True"></asp

ropDownList>
<asp:TextBox id="txtServer" runat="server"
Visible="False"></asp:TextBox>
</td>
</tr>
</table>
</form>
</body>
</HTML>
=========code behind=========
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList lstClient;
protected System.Web.UI.WebControls.DropDownList lstServer;
protected System.Web.UI.WebControls.TextBox txtClient;
protected System.Web.UI.WebControls.TextBox txtServer;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string[] items = {"aaa","bbb","ccc","ddd","eee","fff","ggg","others"};
lstClient.DataSource = lstServer.DataSource = items;
lstClient.DataBind();
lstServer.DataBind();
lstClient.Attributes.Add("onchange","lstClient_change(this)");
txtClient.Style.Add("display","none");
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.lstServer.SelectedIndexChanged += new
System.EventHandler(this.lstServer_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void lstServer_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if(lstServer.SelectedValue == "others")
{
txtServer.Visible = true;
txtServer.Text = "Please input other value";
}
else
{
txtServer.Visible = false;
}
}
}
=====================================
Hope helps. Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)