cannot fire up dropdownlist's SelectedIndexChanged

Discussion in 'ASP .Net' started by Daniel, Jun 8, 2004.

  1. Daniel

    Daniel Guest

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

    Thanks
     
    Daniel, Jun 8, 2004
    #1
    1. Advertising

  2. Set the AutoPostBack property to "true" on the DropDownList.

    Shaun


    "Daniel" <> wrote in message
    news:%...
    > Is there any other way can override this event, like javascript onchange
    > added to the attribute of this dropdownlist?
    >
    > Thanks
    >
    >
     
    Shaun C McDonnell, Jun 8, 2004
    #2
    1. Advertising

  3. Daniel

    Daniel Guest

    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.



    "Shaun C McDonnell" <-spammers-stop.now> wrote in
    message news:%...
    > Set the AutoPostBack property to "true" on the DropDownList.
    >
    > Shaun
    >
    >
    > "Daniel" <> wrote in message
    > news:%...
    > > Is there any other way can override this event, like javascript onchange
    > > added to the attribute of this dropdownlist?
    > >
    > > Thanks
    > >
    > >

    >
    >
     
    Daniel, Jun 9, 2004
    #3
  4. Daniel

    martin Guest

    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



    "Daniel" <> wrote in message
    news:...
    > 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.
    >
    >
    >
    > "Shaun C McDonnell" <-spammers-stop.now> wrote in
    > message news:%...
    > > Set the AutoPostBack property to "true" on the DropDownList.
    > >
    > > Shaun
    > >
    > >
    > > "Daniel" <> wrote in message
    > > news:%...
    > > > Is there any other way can override this event, like javascript

    onchange
    > > > added to the attribute of this dropdownlist?
    > > >
    > > > Thanks
    > > >
    > > >

    > >
    > >

    >
    >
     
    martin, Jun 9, 2004
    #4
  5. Daniel

    avnrao Guest

    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.

    "martin" <> wrote in message
    news:...
    > 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
    >
    >
    >
    > "Daniel" <> wrote in message
    > news:...
    >> 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.
    >>
    >>
    >>
    >> "Shaun C McDonnell" <-spammers-stop.now> wrote in
    >> message news:%...
    >> > Set the AutoPostBack property to "true" on the DropDownList.
    >> >
    >> > Shaun
    >> >
    >> >
    >> > "Daniel" <> wrote in message
    >> > news:%...
    >> > > Is there any other way can override this event, like javascript

    > onchange
    >> > > added to the attribute of this dropdownlist?
    >> > >
    >> > > Thanks
    >> > >
    >> > >
    >> >
    >> >

    >>
    >>

    >
    >
     
    avnrao, Jun 9, 2004
    #5
  6. 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
     
    Steven Cheng[MSFT], Jun 9, 2004
    #6
  7. Daniel

    Daniel Guest

    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!









    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
     
    Daniel, Jun 9, 2004
    #7
  8. 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
     
    Steven Cheng[MSFT], Jun 10, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CW
    Replies:
    2
    Views:
    7,120
  2. Daniel
    Replies:
    2
    Views:
    893
    Steven Cheng[MSFT]
    Jun 9, 2004
  3. Replies:
    2
    Views:
    18,795
  4. Damien
    Replies:
    7
    Views:
    737
    Mark Rae
    Jan 26, 2007
  5. MarkMurphy
    Replies:
    5
    Views:
    438
    Steven Cheng[MSFT]
    Aug 27, 2004
Loading...

Share This Page