problem with postback

Discussion in 'ASP .Net' started by David, Dec 17, 2007.

  1. David

    David Guest

    Hi,

    I have a problem with postback. When the page is postbacked, i want the
    second dropdownlist to be visible if the selectedvalue of the first one
    ="y".
    With this code, it remains invisible. What do i wrong here?
    Thanks
    David

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true>
    <asp:ListItem>x</asp:ListItem>
    <asp:ListItem>y</asp:ListItem>
    </asp:DropDownList>

    <br /> <br />
    <asp:DropDownList ID="DropDownList2" runat="server"
    AutoPostBack=true Visible=false>
    <asp:ListItem>1</asp:ListItem>
    <asp:ListItem>2</asp:ListItem>
    </asp:DropDownList>

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles Me.Load
    If Page.IsPostBack Then
    If DropDownList1.SelectedValue = "y" Then
    DropDownList2.Visible = True
    End if
    End If
    End Sub
     
    David, Dec 17, 2007
    #1
    1. Advertising

  2. David

    David Wier Guest

    why not just put that logic in the SelectedIndexchanged event, making the
    2nd ddl invisible by default.?

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    "David" <> wrote in message
    news:...
    > Hi,
    >
    > I have a problem with postback. When the page is postbacked, i want the
    > second dropdownlist to be visible if the selectedvalue of the first one
    > ="y".
    > With this code, it remains invisible. What do i wrong here?
    > Thanks
    > David
    >
    > <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true>
    > <asp:ListItem>x</asp:ListItem>
    > <asp:ListItem>y</asp:ListItem>
    > </asp:DropDownList>
    >
    > <br /> <br />
    > <asp:DropDownList ID="DropDownList2" runat="server"
    > AutoPostBack=true Visible=false>
    > <asp:ListItem>1</asp:ListItem>
    > <asp:ListItem>2</asp:ListItem>
    > </asp:DropDownList>
    >
    > Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.Load
    > If Page.IsPostBack Then
    > If DropDownList1.SelectedValue = "y" Then
    > DropDownList2.Visible = True
    > End if
    > End If
    > End Sub
    >
    >
    >
    >
     
    David Wier, Dec 17, 2007
    #2
    1. Advertising

  3. David

    David Guest

    Thanks for replying.
    I tried the code within this:
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    ....
    End Sub

    but ddl2 still invisible.
    I don't understand why the Page.IsPostBack doesn't work ...


    "David Wier" <> schreef in bericht
    news:edEwc%...
    > why not just put that logic in the SelectedIndexchanged event, making the
    > 2nd ddl invisible by default.?
    >
    > David Wier
    > http://aspnet101.com
    > http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
    > no bloated markup
    >
    >
    > "David" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> I have a problem with postback. When the page is postbacked, i want the
    >> second dropdownlist to be visible if the selectedvalue of the first one
    >> ="y".
    >> With this code, it remains invisible. What do i wrong here?
    >> Thanks
    >> David
    >>
    >> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true>
    >> <asp:ListItem>x</asp:ListItem>
    >> <asp:ListItem>y</asp:ListItem>
    >> </asp:DropDownList>
    >>
    >> <br /> <br />
    >> <asp:DropDownList ID="DropDownList2" runat="server"
    >> AutoPostBack=true Visible=false>
    >> <asp:ListItem>1</asp:ListItem>
    >> <asp:ListItem>2</asp:ListItem>
    >> </asp:DropDownList>
    >>
    >> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Me.Load
    >> If Page.IsPostBack Then
    >> If DropDownList1.SelectedValue = "y" Then
    >> DropDownList2.Visible = True
    >> End if
    >> End If
    >> End Sub
    >>
    >>
    >>
    >>

    >
    >
     
    David, Dec 17, 2007
    #3
  4. David

    David Wier Guest

    I just tried this:

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    If DropDownList1.SelectedValue = "y" Then DropDownList2.Visible = "True"
    End Sub

    and it worked fine for me

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    "David" <> wrote in message
    news:...
    > Thanks for replying.
    > I tried the code within this:
    > Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    > ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    > ...
    > End Sub
    >
    > but ddl2 still invisible.
    > I don't understand why the Page.IsPostBack doesn't work ...
    >
    >
    > "David Wier" <> schreef in bericht
    > news:edEwc%...
    >> why not just put that logic in the SelectedIndexchanged event, making the
    >> 2nd ddl invisible by default.?
    >>
    >> David Wier
    >> http://aspnet101.com
    >> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
    >> no bloated markup
    >>
    >>
    >> "David" <> wrote in message
    >> news:...
    >>> Hi,
    >>>
    >>> I have a problem with postback. When the page is postbacked, i want the
    >>> second dropdownlist to be visible if the selectedvalue of the first one
    >>> ="y".
    >>> With this code, it remains invisible. What do i wrong here?
    >>> Thanks
    >>> David
    >>>
    >>> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true>
    >>> <asp:ListItem>x</asp:ListItem>
    >>> <asp:ListItem>y</asp:ListItem>
    >>> </asp:DropDownList>
    >>>
    >>> <br /> <br />
    >>> <asp:DropDownList ID="DropDownList2" runat="server"
    >>> AutoPostBack=true Visible=false>
    >>> <asp:ListItem>1</asp:ListItem>
    >>> <asp:ListItem>2</asp:ListItem>
    >>> </asp:DropDownList>
    >>>
    >>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >>> System.EventArgs) Handles Me.Load
    >>> If Page.IsPostBack Then
    >>> If DropDownList1.SelectedValue = "y" Then
    >>> DropDownList2.Visible = True
    >>> End if
    >>> End If
    >>> End Sub
    >>>
    >>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    David Wier, Dec 17, 2007
    #4
  5. David

    David Guest

    In order to check the AutoPostBack only, i reduced the code to this:
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /><br />
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true >
    <asp:ListItem>x</asp:ListItem>
    <asp:ListItem>y</asp:ListItem>
    </asp:DropDownList>

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    If Page.IsPostBack Then
    Label1.Text = "ok"
    End If
    End Sub

    But after having chosen a value in the DDL, the label.text never becomes
    "ok".

    So AutoPostBack doesn't work??? Or i forget to set a parameter or an option
    in web.config or ...?







    "David Wier" <> schreef in bericht
    news:%...
    >I just tried this:
    >
    > Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    > ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    > If DropDownList1.SelectedValue = "y" Then DropDownList2.Visible = "True"
    > End Sub
    >
    > and it worked fine for me
    >
    > David Wier
    > http://aspnet101.com
    > http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
    > no bloated markup
    >
    >
    > "David" <> wrote in message
    > news:...
    >> Thanks for replying.
    >> I tried the code within this:
    >> Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    >> ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    >> ...
    >> End Sub
    >>
    >> but ddl2 still invisible.
    >> I don't understand why the Page.IsPostBack doesn't work ...
    >>
    >>
    >> "David Wier" <> schreef in bericht
    >> news:edEwc%...
    >>> why not just put that logic in the SelectedIndexchanged event, making
    >>> the 2nd ddl invisible by default.?
    >>>
    >>> David Wier
    >>> http://aspnet101.com
    >>> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
    >>> with no bloated markup
    >>>
    >>>
    >>> "David" <> wrote in message
    >>> news:...
    >>>> Hi,
    >>>>
    >>>> I have a problem with postback. When the page is postbacked, i want the
    >>>> second dropdownlist to be visible if the selectedvalue of the first one
    >>>> ="y".
    >>>> With this code, it remains invisible. What do i wrong here?
    >>>> Thanks
    >>>> David
    >>>>
    >>>> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true>
    >>>> <asp:ListItem>x</asp:ListItem>
    >>>> <asp:ListItem>y</asp:ListItem>
    >>>> </asp:DropDownList>
    >>>>
    >>>> <br /> <br />
    >>>> <asp:DropDownList ID="DropDownList2" runat="server"
    >>>> AutoPostBack=true Visible=false>
    >>>> <asp:ListItem>1</asp:ListItem>
    >>>> <asp:ListItem>2</asp:ListItem>
    >>>> </asp:DropDownList>
    >>>>
    >>>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >>>> System.EventArgs) Handles Me.Load
    >>>> If Page.IsPostBack Then
    >>>> If DropDownList1.SelectedValue = "y" Then
    >>>> DropDownList2.Visible = True
    >>>> End if
    >>>> End If
    >>>> End Sub
    >>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    David, Dec 17, 2007
    #5
  6. David

    David Guest

    I have just tested the reduced code with Cassini (included in VWD 2008) and
    .... it works.
    But when i try it with the normal browser IE 7 (with IIS), it doesn't ...

    "David Wier" <> schreef in bericht
    news:%...
    >I just tried this:
    >
    > Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    > ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    > If DropDownList1.SelectedValue = "y" Then DropDownList2.Visible = "True"
    > End Sub
    >
    > and it worked fine for me
    >
    > David Wier
    > http://aspnet101.com
    > http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
    > no bloated markup
    >
    >
    > "David" <> wrote in message
    > news:...
    >> Thanks for replying.
    >> I tried the code within this:
    >> Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    >> ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    >> ...
    >> End Sub
    >>
    >> but ddl2 still invisible.
    >> I don't understand why the Page.IsPostBack doesn't work ...
    >>
    >>
    >> "David Wier" <> schreef in bericht
    >> news:edEwc%...
    >>> why not just put that logic in the SelectedIndexchanged event, making
    >>> the 2nd ddl invisible by default.?
    >>>
    >>> David Wier
    >>> http://aspnet101.com
    >>> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
    >>> with no bloated markup
    >>>
    >>>
    >>> "David" <> wrote in message
    >>> news:...
    >>>> Hi,
    >>>>
    >>>> I have a problem with postback. When the page is postbacked, i want the
    >>>> second dropdownlist to be visible if the selectedvalue of the first one
    >>>> ="y".
    >>>> With this code, it remains invisible. What do i wrong here?
    >>>> Thanks
    >>>> David
    >>>>
    >>>> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true>
    >>>> <asp:ListItem>x</asp:ListItem>
    >>>> <asp:ListItem>y</asp:ListItem>
    >>>> </asp:DropDownList>
    >>>>
    >>>> <br /> <br />
    >>>> <asp:DropDownList ID="DropDownList2" runat="server"
    >>>> AutoPostBack=true Visible=false>
    >>>> <asp:ListItem>1</asp:ListItem>
    >>>> <asp:ListItem>2</asp:ListItem>
    >>>> </asp:DropDownList>
    >>>>
    >>>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >>>> System.EventArgs) Handles Me.Load
    >>>> If Page.IsPostBack Then
    >>>> If DropDownList1.SelectedValue = "y" Then
    >>>> DropDownList2.Visible = True
    >>>> End if
    >>>> End If
    >>>> End Sub
    >>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    David, Dec 17, 2007
    #6
  7. David

    David Guest

    Ok, i began it from the beginning and now it works. Strange ...
    "David Wier" <> schreef in bericht
    news:%...
    >I just tried this:
    >
    > Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    > ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    > If DropDownList1.SelectedValue = "y" Then DropDownList2.Visible = "True"
    > End Sub
    >
    > and it worked fine for me
    >
    > David Wier
    > http://aspnet101.com
    > http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with
    > no bloated markup
    >
    >
    > "David" <> wrote in message
    > news:...
    >> Thanks for replying.
    >> I tried the code within this:
    >> Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    >> ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    >> ...
    >> End Sub
    >>
    >> but ddl2 still invisible.
    >> I don't understand why the Page.IsPostBack doesn't work ...
    >>
    >>
    >> "David Wier" <> schreef in bericht
    >> news:edEwc%...
    >>> why not just put that logic in the SelectedIndexchanged event, making
    >>> the 2nd ddl invisible by default.?
    >>>
    >>> David Wier
    >>> http://aspnet101.com
    >>> http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML
    >>> with no bloated markup
    >>>
    >>>
    >>> "David" <> wrote in message
    >>> news:...
    >>>> Hi,
    >>>>
    >>>> I have a problem with postback. When the page is postbacked, i want the
    >>>> second dropdownlist to be visible if the selectedvalue of the first one
    >>>> ="y".
    >>>> With this code, it remains invisible. What do i wrong here?
    >>>> Thanks
    >>>> David
    >>>>
    >>>> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack=true>
    >>>> <asp:ListItem>x</asp:ListItem>
    >>>> <asp:ListItem>y</asp:ListItem>
    >>>> </asp:DropDownList>
    >>>>
    >>>> <br /> <br />
    >>>> <asp:DropDownList ID="DropDownList2" runat="server"
    >>>> AutoPostBack=true Visible=false>
    >>>> <asp:ListItem>1</asp:ListItem>
    >>>> <asp:ListItem>2</asp:ListItem>
    >>>> </asp:DropDownList>
    >>>>
    >>>> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    >>>> System.EventArgs) Handles Me.Load
    >>>> If Page.IsPostBack Then
    >>>> If DropDownList1.SelectedValue = "y" Then
    >>>> DropDownList2.Visible = True
    >>>> End if
    >>>> End If
    >>>> End Sub
    >>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    David, Dec 17, 2007
    #7
    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. Psych971
    Replies:
    5
    Views:
    4,631
    bruce barker
    Dec 17, 2004
  2. =?Utf-8?B?Q2hhZA==?=

    Postback not being set to True on first postback

    =?Utf-8?B?Q2hhZA==?=, Apr 4, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    510
    =?Utf-8?B?Q2hhZA==?=
    Apr 4, 2005
  3. gce
    Replies:
    2
    Views:
    1,722
  4. Jacky Chau
    Replies:
    2
    Views:
    2,066
    Ninjamyst
    Jun 8, 2005
  5. Fabio Mastria
    Replies:
    5
    Views:
    4,360
    TechMCAD13
    Jan 30, 2008
Loading...

Share This Page