question about postback and viewstate

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben

    question about postback and viewstate

    Hi,

    There are two radiobuttonlist s created and fed dynamically. Both has
    AutoPostBack=Tr ue.
    When an option of a radiobuttonlist is checked, its ID and its selectedvalue
    must appear on screen (with response.write) . The property EnableViewState is
    set to False for the page.

    It works but i have two questions about this:

    1) when i start by clicking e.g. option 2 of radiobuttonlist 1 (ID=rb1), i
    see according the code below: rb1 2

    My question is: how can the server, after loading the postback data, assign
    it to radiobuttonlist 1? At the moment of the load postback data step in the
    Page Life Cycle, the control radiobuttonlist 1 doesn't exist yet, because
    it's created dynamically during the Page_Load event (which comes later) ?

    2) Now, after having clicking on option 2 of radiobuttonlist 1, clicking
    e.g. on option 1 of radiobuttonlist 2 (ID=rb2) shows on screen: rb1 2 rb2 1

    My question is: why do i still see: rb1 2? I expect to see only rb2 1,
    because the SelectedIndex of radiobuttonlist 1 hasn't changed. Obviously,
    both radiobuttonlist 1 and radiobuttonlist 2 passed trhough procedure
    "radiod", but why radiobuttonlist 1 because its selectedindex remained the
    same?

    I also tried with EnableViewState =True, and then i see only rb2 1 ... Why?

    Thanks
    Ben

    The code:
    --------
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
    Handles Me.Load
    Dim rb1, rb2 As RadioButtonList
    Dim z1, z2 As ListItem

    rb1 = New RadioButtonList
    rb1.AutoPostBac k = True
    rb1.ID = "rb1"
    z1 = New ListItem("optio n 1 of radio 1", "1")
    z2 = New ListItem("optio n 2 of radio 1", "2")
    rb1.Items.Add(z 1)
    rb1.Items.Add(z 2)
    form1.Controls. Add(rb1)

    AddHandler rb1.SelectedInd exChanged, AddressOf radiod

    rb2 = New RadioButtonList
    rb2.AutoPostBac k = True
    rb2.ID = "rb2"
    z1 = New ListItem("optio n 1 of radio 2", "1")
    z2 = New ListItem("optio n 2 of radio 2", "2")
    rb2.Items.Add(z 1)
    rb2.Items.Add(z 2)
    form1.Controls. Add(rb2)

    AddHandler rb2.SelectedInd exChanged, AddressOf radiod

    End Sub

    Protected Sub radiod(ByVal sender As Object, ByVal e As System.EventArg s)
    Dim rb As RadioButtonList = CType(sender, RadioButtonList )
    Response.Write( rb.ID & " " & rb.SelectedValu e & " ")
    End Sub


  • Teemu Keiski

    #2
    Re: question about postback and viewstate

    I replied to your first question on forums.
    A broad category of Microsoft tools, languages, and frameworks for software development. Designed to support developers in building, debugging, and deploying applications across various platforms.


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP





    "Ben" <ben@sdf.sfswro te in message
    news:%235sGzBL9 IHA.1200@TK2MSF TNGP04.phx.gbl. ..
    Hi,
    >
    There are two radiobuttonlist s created and fed dynamically. Both has
    AutoPostBack=Tr ue.
    When an option of a radiobuttonlist is checked, its ID and its
    selectedvalue must appear on screen (with response.write) . The property
    EnableViewState is set to False for the page.
    >
    It works but i have two questions about this:
    >
    1) when i start by clicking e.g. option 2 of radiobuttonlist 1 (ID=rb1), i
    see according the code below: rb1 2
    >
    My question is: how can the server, after loading the postback data,
    assign it to radiobuttonlist 1? At the moment of the load postback data
    step in the Page Life Cycle, the control radiobuttonlist 1 doesn't exist
    yet, because it's created dynamically during the Page_Load event (which
    comes later) ?
    >
    2) Now, after having clicking on option 2 of radiobuttonlist 1, clicking
    e.g. on option 1 of radiobuttonlist 2 (ID=rb2) shows on screen: rb1 2 rb2
    1
    >
    My question is: why do i still see: rb1 2? I expect to see only rb2 1,
    because the SelectedIndex of radiobuttonlist 1 hasn't changed. Obviously,
    both radiobuttonlist 1 and radiobuttonlist 2 passed trhough procedure
    "radiod", but why radiobuttonlist 1 because its selectedindex remained the
    same?
    >
    I also tried with EnableViewState =True, and then i see only rb2 1 ... Why?
    >
    Thanks
    Ben
    >
    The code:
    --------
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles Me.Load
    Dim rb1, rb2 As RadioButtonList
    Dim z1, z2 As ListItem
    >
    rb1 = New RadioButtonList
    rb1.AutoPostBac k = True
    rb1.ID = "rb1"
    z1 = New ListItem("optio n 1 of radio 1", "1")
    z2 = New ListItem("optio n 2 of radio 1", "2")
    rb1.Items.Add(z 1)
    rb1.Items.Add(z 2)
    form1.Controls. Add(rb1)
    >
    AddHandler rb1.SelectedInd exChanged, AddressOf radiod
    >
    rb2 = New RadioButtonList
    rb2.AutoPostBac k = True
    rb2.ID = "rb2"
    z1 = New ListItem("optio n 1 of radio 2", "1")
    z2 = New ListItem("optio n 2 of radio 2", "2")
    rb2.Items.Add(z 1)
    rb2.Items.Add(z 2)
    form1.Controls. Add(rb2)
    >
    AddHandler rb2.SelectedInd exChanged, AddressOf radiod
    >
    End Sub
    >
    Protected Sub radiod(ByVal sender As Object, ByVal e As System.EventArg s)
    Dim rb As RadioButtonList = CType(sender, RadioButtonList )
    Response.Write( rb.ID & " " & rb.SelectedValu e & " ")
    End Sub
    >

    Comment

    Working...