DropDownList Control and AutoPostBack problems

G

Girish

1) I have a dropdownlist control with AutoPostBack property set to true.
2) For the same control I have a SelectedIndexChanged method call in my code
behind.
3) What I would like to accomplish is IF the selected text in the drop down
is "Teacher", another control should be set to invisible.

Heres the code behind:
private void classification_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if (classification.SelectedValue == "Teacher")
{
intEduLevel.Visible = false;
}
}

Now, when I start debugging this application - the debugger stops at this
javascript code generated by the control.
THIS HAPPENS When I CHANGE the selection on the DropDownList control.

<script language="javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
theform = document.forms["Form2"];
}
else {
theform = document.Form2;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit(); //<<<-------------------------- RIGHT
HERE!!!!!!!!!!!!!!!!!
}
// -->
</script>


The error is :"JScript Runtime error: Object dosent support this property or
method"


Here are some other details:
MY IE Version: 6.0.28
My project is set to target IE 3.02 and Netscape 3.0 Browsers

If anyone can tell me what this problem is, Id greatly appreciate it.

Thanks,
Girish
 
S

Steven Cheng[MSFT]

Hi Girish,


Thanks for posting in the community!
From your description, you used a ASP.NET DropDownList in a web form and it
it set as AutoPostBack = true so as to capture it's selectedindeschanged
serverside event. However, when running the page, you found that there
occured the below error:
The error is :"JScript Runtime error: Object dosent support this property or
method"
at the clientside script , yes?

If there is anything I misunderstood, please feel free to let me know.


Based on my experience, such odd errors is likely caused by some unexpected
things. Have you ever met such errors before or is it a common situation? I
recommend that you try the following steps:
1. Try creating a new simple page and add a DropDownList to test its
SelectedindexChanged event. If ok, you 'll check the difference bewteen
the two pages.

2. Trying do the same test on a certain page in other project. If the
problem goes away, try checking if there're any difference between the two
pages.

Also, here is a test page I used to test on my side, you may try testing on
it if you feel necessary:
-------------------------------------aspx
page----------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DropDownList</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>Category:
<asp:dropdownlist id="lstCategory" runat="server" AutoPostBack="True">
<asp:ListItem Value="Student" Selected="True">Student</asp:ListItem>
<asp:ListItem Value="Teacher">Teacher</asp:ListItem>
</asp:dropdownlist></td>
</tr>
<tr>
<td><asp:panel id="pnlStudent" runat="server" Visible="True">
<TABLE>
<TR>
<TD colSpan="2">
<asp:Label id="lblTitleS" runat="server">Student's
Info</asp:Label></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label1" runat="server">ID:</asp:Label></TD>
<TD>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label2" runat="server">Name:</asp:Label></TD>
<TD>
<asp:TextBox id="TextBox2" runat="server"></asp:TextBox></TD>
</TR>
</TABLE>
</asp:panel></td>
</tr>
<tr>
<td><asp:panel id="pnlTeacher" runat="server" Visible="False">
<TABLE>
<TR>
<TD colSpan="2">
<asp:Label id="lblTitleT" runat="server">Teacher's
Info</asp:Label></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label3" runat="server">ID:</asp:Label></TD>
<TD>
<asp:TextBox id="TextBox3" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>
<asp:Label id="Label4" runat="server">Name:</asp:Label></TD>
<TD>
<asp:TextBox id="TextBox4" runat="server"></asp:TextBox></TD>
</TR>
</TABLE>
</asp:panel></td>
</tr>
</table>
</form>
</body>
</HTML>


-----------------------------code behind page
class----------------------------
public class DropDownList : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList lstCategory;
protected System.Web.UI.WebControls.Panel pnlStudent;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.TextBox TextBox4;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label lblTitleS;
protected System.Web.UI.WebControls.Label lblTitleT;
protected System.Web.UI.WebControls.Panel pnlTeacher;

private void Page_Load(object sender, System.EventArgs e)
{
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lstCategory.SelectedIndexChanged += new
System.EventHandler(this.lstCategory_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void lstCategory_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if(lstCategory.SelectedValue.Equals("Teacher"))
{
pnlTeacher.Visible = true;
pnlStudent.Visible = false;
}
else
{
pnlTeacher.Visible = false;
pnlStudent.Visible = true;
}
}
}
------------------------------------------------------------

Please try out the preceding suggestions. If you need any assistance,
please feel free to post here.



Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

Girish

Thanks Steven,

I figured the problem. It had to do with the submit buttons name being
"submit".

Girish
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top