cannot fire up dropdownlist's SelectedIndexChanged

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

Is there any other way can override this event, like javascript onchange
added to the attribute of this dropdownlist?

Thanks
 
Yes, i've done that, but still cannot fire up, there is a javascript
onChange on this dropdownlist, i wonder it will affect this.

Thanks.
 
try returning "true" from the dropdown list

<select ddl... onchange="myevent();return true;"

I noticed that I had to use this method on a checkbox that poste back.

make sure that true is returne before the call to the .net generated
javascript.

HTH

cheers

martin
 
you said you are adding it as an attribute..
if you are doing this..
DropDownList1.Attributes.Add("onchange","alert(2);return;");
make sure that you should not have the return status after your javascript
executes. remove the RETURN from above line.

asp.net spits out the html like this..
<select name="DropDownList1"
onchange="alert(2);return;__doPostBack('DropDownList1','')"..
so having return on onchange would not fire post back.

Av.
 
HI Daniel,

I've also found some other former threads you posted discussing on this
problem. Since this is a strange behavior , I'd like to confirm some other
things:
1. Are there any other controls which can autopostback such as "TextBox" ,
"CheckBox" also suffering the problem?

2. Does this problem occur in many pages or just one particular page?

3. What about creating a new simple web project and a page to do the same
test?

Here is a test page I use to test on my side, please have a check to see
whether it works.

==================aspx page=====================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>AutoPostBack</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td>
<asp:TextBox id="TextBox1" runat="server"
AutoPostBack="True"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:DropDownList id="DropDownList1" runat="server"
AutoPostBack="True">
<asp:ListItem Value="aaa" Selected="True">aaa</asp:ListItem>
<asp:ListItem Value="bbb">bbb</asp:ListItem>
<asp:ListItem Value="ccc">ccc</asp:ListItem>
<asp:ListItem Value="ddd">ddd</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td>
<asp:ListBox id="ListBox1" runat="server" AutoPostBack="True">
<asp:ListItem Value="aaa">aaa</asp:ListItem>
<asp:ListItem Value="bbb">bbb</asp:ListItem>
<asp:ListItem Value="ccc">ccc</asp:ListItem>
<asp:ListItem Value="ddd">ddd</asp:ListItem>
</asp:ListBox></td>
</tr>
</table>
</form>
</body>
</HTML>

==============code behind=====================
Public Class AutoPostBack
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents DropDownList1 As
System.Web.UI.WebControls.DropDownList
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox

'NOTE: The following placeholder declaration is required by the Web
Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles TextBox1.TextChanged
Response.Write("TextBox1 is AutoPostBack!")
End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
Response.Write("DropDownList1 is AutoPostBack!")
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
Response.Write("ListBox1 is AutoPostBack!")
End Sub
End Class
=====================================================

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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Hi, steven

There is a listbox on the same page, on the design page, i double click
this, and in the code behind i have the below, and i make it autopostback
true.
Private Sub lstCTSUnit_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lstCTSUnit.SelectedIndexChanged

Response.Write("Test from Fei")

End Sub

It doesnot work!

Strange, AND i really need help!

Thanks!
 
Hi Daniel,

What about the demo page I provided in the last reply? Is it also not
working? If a new created page or even a simple page in a new created
project still suffering the problem. I'm afraid there must be some thing
incorrect with the ASP.NET 's installation on the machine. You can try use
the aspnet_regiis.exe tool in the
"{driver}:\WINDOWS\Microsoft.NET\Framework\v1.1.4322" folder and type the
following command:

aspnet_regiis -u
aspnet_regiis -i

to uninstall and reinstall the ASP.NET on the machine. Thanks

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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Back
Top