Sending data with post back.

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

    Sending data with post back.

    Am I correct to assume that any changes to a control's properties or changes
    to a ViewState("Name ") are not available until after the Page_Load fires?

    If so, how can you set a flag in a control event so that you can take action
    on postback?

    I have the following code..... The window.alert always reads 0


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArg s) Handles MyBase.Load

    'Put user code to initialize the page here

    If not ispostback then

    textbox1.text = 0

    end if

    Response.Write( "<script language=javasc ript>window.ale rt('textbox1 = " &
    TextBox1.Text & "')</script>")

    End Sub


    Private Sub button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles btnBindContacts .Click

    TextBox1.Text = 1

    ViewState("Call Type") = 1

    End Sub


  • Kairi Zikpin

    #2
    Re: Sending data with post back.

    the question in your case is not really when the values are available.
    the real question is in what order do things happen?

    page load event fires BEFORE your button_click event therefore when you
    do a response.write, textbox still has the original value. that is why
    on the FIRST run the alert shows a value of zero. additonally, once you
    click ok on the alert, the text box still has a zero so when you click
    the button, the alert will again show zero. That's because the
    response.write occurs BEFORE the button_click is processed.

    However, this time the text box shows 1. So once you click the button
    the second time, the alert shows what you expect. I ran the exact code
    you posted and that is the output I got.

    Basically you need to change the order of your code. Also, if you had
    used the debugger that comes with visual studio, you would have noticed
    the error.


    Jim Mitchell wrote:[color=blue]
    > Am I correct to assume that any changes to a control's properties or changes
    > to a ViewState("Name ") are not available until after the Page_Load fires?
    >
    > If so, how can you set a flag in a control event so that you can take action
    > on postback?
    >
    > I have the following code..... The window.alert always reads 0
    >
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles MyBase.Load
    >
    > 'Put user code to initialize the page here
    >
    > If not ispostback then
    >
    > textbox1.text = 0
    >
    > end if
    >
    > Response.Write( "<script language=javasc ript>window.ale rt('textbox1 = " &
    > TextBox1.Text & "')</script>")
    >
    > End Sub
    >
    >
    > Private Sub button1_Click(B yVal sender As System.Object, ByVal e As
    > System.EventArg s) Handles btnBindContacts .Click
    >
    > TextBox1.Text = 1
    >
    > ViewState("Call Type") = 1
    >
    > End Sub
    >
    >[/color]

    Comment

    • Kairi Zikpin

      #3
      Re: Sending data with post back.

      to answer your other question, viewstate is restored during page_init
      which happens before page_load.

      also, i think the real problem you are having is where to put your code.
      do not take action on postback in the page_lod event (in this case).
      instead, take action in the bottun's click event since you are
      responding to the click event.

      i'd encourage you to do some reading on event handlers. a good start
      would be the following link (in internet explorer) provided you have the
      visual studio.net documentation installed:

      ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWebFormsPa geProcessingSta ges.htm

      Jim Mitchell wrote:
      [color=blue]
      > Am I correct to assume that any changes to a control's properties or changes
      > to a ViewState("Name ") are not available until after the Page_Load fires?
      >
      > If so, how can you set a flag in a control event so that you can take action
      > on postback?
      >
      > I have the following code..... The window.alert always reads 0
      >
      >
      > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
      > System.EventArg s) Handles MyBase.Load
      >
      > 'Put user code to initialize the page here
      >
      > If not ispostback then
      >
      > textbox1.text = 0
      >
      > end if
      >
      > Response.Write( "<script language=javasc ript>window.ale rt('textbox1 = " &
      > TextBox1.Text & "')</script>")
      >
      > End Sub
      >
      >
      > Private Sub button1_Click(B yVal sender As System.Object, ByVal e As
      > System.EventArg s) Handles btnBindContacts .Click
      >
      > TextBox1.Text = 1
      >
      > ViewState("Call Type") = 1
      >
      > End Sub
      >
      >[/color]

      Comment

      • Jim Mitchell

        #4
        Re: Sending data with post back.

        Thank you for the very detailed answer. I guess I was trying to force
        something to happen in the page_load event chasing a challenge I have posted
        in the Datagrid forum. Nevertheless, your answer reconfirmed the way I
        thought it should be happening. I will take your suggestion on the event
        reading. If you think you might be able to help, I am taking action in the
        button_click event as shown below, but when I load a column in a datagrid at
        run time with no columns at design time (and no autogenerate columns), my
        datagrid dissappears on postback.

        Everyone was saying to "make sure you bind the datagrid on postback" and
        since binding in the button_click was not working, I kept trying to put it
        in the load page event. The code below works perfectly if I have even one
        column defined at design time, but as soon as I take all columns out at
        design time, everything falls apart.

        Thanks again for your help. Maybe you can catch something below that we are
        missing.

        Jim




        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles MyBase.Load
        If Not IsPostBack Then
        BindGrid("Compa ny")
        End If
        End Sub

        Private Sub btnFillOne_Clic k(ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles btnFillOne.Clic k

        BindGrid("Compa ny")

        End Sub


        Private Sub btnFillTwo_Clic k(ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles btnFillTwo.Clic k

        BindGrid("Conta ct")

        End Sub

        Sub BindGrid(ByVal field_name)

        Dim mycn As SqlClient.SqlCo nnection

        Dim daAccounts As SqlClient.SqlDa taAdapter

        Dim dsAccounts As New DataSet

        Dim mysql As String

        mycn = New
        SqlClient.SqlCo nnection(System .Configuration. ConfigurationSe ttings.AppSetti n
        gs("ConnectStri ng"))

        DataGrid1.Colum ns.Clear()

        Dim dcolumn As System.Web.UI.W ebControls.Butt onColumn

        dcolumn = New System.Web.UI.W ebControls.Butt onColumn

        dcolumn.ButtonT ype = ButtonColumnTyp e.LinkButton

        dcolumn.DataTex tField = field_name

        dcolumn.HeaderT ext = field_name

        dcolumn.Command Name = "Select"

        dcolumn.Text = "Select"

        If field_name = "Company" Then mysql = "Select * from tblCompanys"

        If field_name = "Contact" Then mysql = "Select * from tblContacts"

        daAccounts = New SqlClient.SqlDa taAdapter(mysql , mycn)

        daAccounts.Fill (dsAccounts)

        DataGrid1.DataS ource = dsAccounts

        DataGrid1.DataK eyField = "ID"

        DataGrid1.Colum ns.Add(dcolumn)

        DataGrid1.DataB ind()

        mycn.Close()

        End Sub






        "Kairi Zikpin" <zikkai.nospam. @netscape.net> wrote in message
        news:YST1b.8226 46$3C2.18622897 @news3.calgary. shaw.ca...[color=blue]
        > to answer your other question, viewstate is restored during page_init
        > which happens before page_load.
        >
        > also, i think the real problem you are having is where to put your code.
        > do not take action on postback in the page_lod event (in this case).
        > instead, take action in the bottun's click event since you are
        > responding to the click event.
        >
        > i'd encourage you to do some reading on event handlers. a good start
        > would be the following link (in internet explorer) provided you have the
        > visual studio.net documentation installed:
        >
        >[/color]
        ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWebFormsPa geProcessingSta ges.htm[color=blue]
        >
        > Jim Mitchell wrote:
        >[color=green]
        > > Am I correct to assume that any changes to a control's properties or[/color][/color]
        changes[color=blue][color=green]
        > > to a ViewState("Name ") are not available until after the Page_Load[/color][/color]
        fires?[color=blue][color=green]
        > >
        > > If so, how can you set a flag in a control event so that you can take[/color][/color]
        action[color=blue][color=green]
        > > on postback?
        > >
        > > I have the following code..... The window.alert always reads 0
        > >
        > >
        > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
        > > System.EventArg s) Handles MyBase.Load
        > >
        > > 'Put user code to initialize the page here
        > >
        > > If not ispostback then
        > >
        > > textbox1.text = 0
        > >
        > > end if
        > >
        > > Response.Write( "<script language=javasc ript>window.ale rt('textbox1 = " &
        > > TextBox1.Text & "')</script>")
        > >
        > > End Sub
        > >
        > >
        > > Private Sub button1_Click(B yVal sender As System.Object, ByVal e As
        > > System.EventArg s) Handles btnBindContacts .Click
        > >
        > > TextBox1.Text = 1
        > >
        > > ViewState("Call Type") = 1
        > >
        > > End Sub
        > >
        > >[/color]
        >[/color]


        Comment

        • JD

          #5
          Re: Sending data with post back.

          > to answer your other question, viewstate is restored during page_init[color=blue]
          > which happens before page_load.[/color]


          I don't think this is correct. I think its in the method loadviewstate that
          viewstate gets restored. This happens before page load but after page init
          and it only happens on postbacks.

          - J

          "Kairi Zikpin" <zikkai.nospam. @netscape.net> wrote in message
          news:YST1b.8226 46$3C2.18622897 @news3.calgary. shaw.ca...[color=blue]
          > to answer your other question, viewstate is restored during page_init
          > which happens before page_load.
          >
          > also, i think the real problem you are having is where to put your code.
          > do not take action on postback in the page_lod event (in this case).
          > instead, take action in the bottun's click event since you are
          > responding to the click event.
          >
          > i'd encourage you to do some reading on event handlers. a good start
          > would be the following link (in internet explorer) provided you have the
          > visual studio.net documentation installed:
          >
          >[/color]
          ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWebFormsPa geProcessingSta ges.htm[color=blue]
          >
          > Jim Mitchell wrote:
          >[color=green]
          > > Am I correct to assume that any changes to a control's properties or[/color][/color]
          changes[color=blue][color=green]
          > > to a ViewState("Name ") are not available until after the Page_Load[/color][/color]
          fires?[color=blue][color=green]
          > >
          > > If so, how can you set a flag in a control event so that you can take[/color][/color]
          action[color=blue][color=green]
          > > on postback?
          > >
          > > I have the following code..... The window.alert always reads 0
          > >
          > >
          > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
          > > System.EventArg s) Handles MyBase.Load
          > >
          > > 'Put user code to initialize the page here
          > >
          > > If not ispostback then
          > >
          > > textbox1.text = 0
          > >
          > > end if
          > >
          > > Response.Write( "<script language=javasc ript>window.ale rt('textbox1 = " &
          > > TextBox1.Text & "')</script>")
          > >
          > > End Sub
          > >
          > >
          > > Private Sub button1_Click(B yVal sender As System.Object, ByVal e As
          > > System.EventArg s) Handles btnBindContacts .Click
          > >
          > > TextBox1.Text = 1
          > >
          > > ViewState("Call Type") = 1
          > >
          > > End Sub
          > >
          > >[/color]
          >[/color]


          Comment

          • Kairi Zikpin

            #6
            Re: Sending data with post back.

            i just did this with no columns defined at run time and it works.
            however i have autogenerate turned on. i don't see anywhere in your code
            that you generate the columns, so if you turn off autogenerate, how do
            you expect columns to show up?

            Jim Mitchell wrote:[color=blue]
            > Thank you for the very detailed answer. I guess I was trying to force
            > something to happen in the page_load event chasing a challenge I have posted
            > in the Datagrid forum. Nevertheless, your answer reconfirmed the way I
            > thought it should be happening. I will take your suggestion on the event
            > reading. If you think you might be able to help, I am taking action in the
            > button_click event as shown below, but when I load a column in a datagrid at
            > run time with no columns at design time (and no autogenerate columns), my
            > datagrid dissappears on postback.
            >
            > Everyone was saying to "make sure you bind the datagrid on postback" and
            > since binding in the button_click was not working, I kept trying to put it
            > in the load page event. The code below works perfectly if I have even one
            > column defined at design time, but as soon as I take all columns out at
            > design time, everything falls apart.
            >
            > Thanks again for your help. Maybe you can catch something below that we are
            > missing.
            >
            > Jim
            >
            >
            >
            >
            > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
            > System.EventArg s) Handles MyBase.Load
            > If Not IsPostBack Then
            > BindGrid("Compa ny")
            > End If
            > End Sub
            >
            > Private Sub btnFillOne_Clic k(ByVal sender As System.Object, ByVal e As
            > System.EventArg s) Handles btnFillOne.Clic k
            >
            > BindGrid("Compa ny")
            >
            > End Sub
            >
            >
            > Private Sub btnFillTwo_Clic k(ByVal sender As System.Object, ByVal e As
            > System.EventArg s) Handles btnFillTwo.Clic k
            >
            > BindGrid("Conta ct")
            >
            > End Sub
            >
            > Sub BindGrid(ByVal field_name)
            >
            > Dim mycn As SqlClient.SqlCo nnection
            >
            > Dim daAccounts As SqlClient.SqlDa taAdapter
            >
            > Dim dsAccounts As New DataSet
            >
            > Dim mysql As String
            >
            > mycn = New
            > SqlClient.SqlCo nnection(System .Configuration. ConfigurationSe ttings.AppSetti n
            > gs("ConnectStri ng"))
            >
            > DataGrid1.Colum ns.Clear()
            >
            > Dim dcolumn As System.Web.UI.W ebControls.Butt onColumn
            >
            > dcolumn = New System.Web.UI.W ebControls.Butt onColumn
            >
            > dcolumn.ButtonT ype = ButtonColumnTyp e.LinkButton
            >
            > dcolumn.DataTex tField = field_name
            >
            > dcolumn.HeaderT ext = field_name
            >
            > dcolumn.Command Name = "Select"
            >
            > dcolumn.Text = "Select"
            >
            > If field_name = "Company" Then mysql = "Select * from tblCompanys"
            >
            > If field_name = "Contact" Then mysql = "Select * from tblContacts"
            >
            > daAccounts = New SqlClient.SqlDa taAdapter(mysql , mycn)
            >
            > daAccounts.Fill (dsAccounts)
            >
            > DataGrid1.DataS ource = dsAccounts
            >
            > DataGrid1.DataK eyField = "ID"
            >
            > DataGrid1.Colum ns.Add(dcolumn)
            >
            > DataGrid1.DataB ind()
            >
            > mycn.Close()
            >
            > End Sub
            >
            >
            >
            >
            >
            >
            > "Kairi Zikpin" <zikkai.nospam. @netscape.net> wrote in message
            > news:YST1b.8226 46$3C2.18622897 @news3.calgary. shaw.ca...
            >[color=green]
            >>to answer your other question, viewstate is restored during page_init
            >>which happens before page_load.
            >>
            >>also, i think the real problem you are having is where to put your code.
            >>do not take action on postback in the page_lod event (in this case).
            >>instead, take action in the bottun's click event since you are
            >>responding to the click event.
            >>
            >>i'd encourage you to do some reading on event handlers. a good start
            >>would be the following link (in internet explorer) provided you have the
            >>visual studio.net documentation installed:
            >>
            >>[/color]
            >
            > ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWebFormsPa geProcessingSta ges.htm
            >[color=green]
            >>Jim Mitchell wrote:
            >>
            >>[color=darkred]
            >>>Am I correct to assume that any changes to a control's properties or[/color][/color]
            >
            > changes
            >[color=green][color=darkred]
            >>>to a ViewState("Name ") are not available until after the Page_Load[/color][/color]
            >
            > fires?
            >[color=green][color=darkred]
            >>>If so, how can you set a flag in a control event so that you can take[/color][/color]
            >
            > action
            >[color=green][color=darkred]
            >>>on postback?
            >>>
            >>>I have the following code..... The window.alert always reads 0
            >>>
            >>>
            >>>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
            >>>System.Event Args) Handles MyBase.Load
            >>>
            >>>'Put user code to initialize the page here
            >>>
            >>>If not ispostback then
            >>>
            >>> textbox1.text = 0
            >>>
            >>>end if
            >>>
            >>>Response.Wri te("<script language=javasc ript>window.ale rt('textbox1 = " &
            >>>TextBox1.Tex t & "')</script>")
            >>>
            >>>End Sub
            >>>
            >>>
            >>>Private Sub button1_Click(B yVal sender As System.Object, ByVal e As
            >>>System.Event Args) Handles btnBindContacts .Click
            >>>
            >>>TextBox1.Tex t = 1
            >>>
            >>>ViewState("C allType") = 1
            >>>
            >>>End Sub
            >>>
            >>>[/color]
            >>[/color]
            >
            >[/color]

            Comment

            • Jim Mitchell

              #7
              Re: Sending data with post back.

              The bindgrid routine adds the columns at run time from the btn click event.

              Jim


              "Kairi Zikpin" <zikkai.nospam. @netscape.net> wrote in message
              news:9R72b.1566 3$la.282727@new s1.calgary.shaw .ca...[color=blue]
              > i just did this with no columns defined at run time and it works.
              > however i have autogenerate turned on. i don't see anywhere in your code
              > that you generate the columns, so if you turn off autogenerate, how do
              > you expect columns to show up?
              >
              > Jim Mitchell wrote:[color=green]
              > > Thank you for the very detailed answer. I guess I was trying to force
              > > something to happen in the page_load event chasing a challenge I have[/color][/color]
              posted[color=blue][color=green]
              > > in the Datagrid forum. Nevertheless, your answer reconfirmed the way I
              > > thought it should be happening. I will take your suggestion on the[/color][/color]
              event[color=blue][color=green]
              > > reading. If you think you might be able to help, I am taking action in[/color][/color]
              the[color=blue][color=green]
              > > button_click event as shown below, but when I load a column in a[/color][/color]
              datagrid at[color=blue][color=green]
              > > run time with no columns at design time (and no autogenerate columns),[/color][/color]
              my[color=blue][color=green]
              > > datagrid dissappears on postback.
              > >
              > > Everyone was saying to "make sure you bind the datagrid on postback" and
              > > since binding in the button_click was not working, I kept trying to put[/color][/color]
              it[color=blue][color=green]
              > > in the load page event. The code below works perfectly if I have even[/color][/color]
              one[color=blue][color=green]
              > > column defined at design time, but as soon as I take all columns out at
              > > design time, everything falls apart.
              > >
              > > Thanks again for your help. Maybe you can catch something below that we[/color][/color]
              are[color=blue][color=green]
              > > missing.
              > >
              > > Jim
              > >
              > >
              > >
              > >
              > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
              > > System.EventArg s) Handles MyBase.Load
              > > If Not IsPostBack Then
              > > BindGrid("Compa ny")
              > > End If
              > > End Sub
              > >
              > > Private Sub btnFillOne_Clic k(ByVal sender As System.Object, ByVal e As
              > > System.EventArg s) Handles btnFillOne.Clic k
              > >
              > > BindGrid("Compa ny")
              > >
              > > End Sub
              > >
              > >
              > > Private Sub btnFillTwo_Clic k(ByVal sender As System.Object, ByVal e As
              > > System.EventArg s) Handles btnFillTwo.Clic k
              > >
              > > BindGrid("Conta ct")
              > >
              > > End Sub
              > >
              > > Sub BindGrid(ByVal field_name)
              > >
              > > Dim mycn As SqlClient.SqlCo nnection
              > >
              > > Dim daAccounts As SqlClient.SqlDa taAdapter
              > >
              > > Dim dsAccounts As New DataSet
              > >
              > > Dim mysql As String
              > >
              > > mycn = New
              > >[/color][/color]
              SqlClient.SqlCo nnection(System .Configuration. ConfigurationSe ttings.AppSetti n[color=blue][color=green]
              > > gs("ConnectStri ng"))
              > >
              > > DataGrid1.Colum ns.Clear()
              > >
              > > Dim dcolumn As System.Web.UI.W ebControls.Butt onColumn
              > >
              > > dcolumn = New System.Web.UI.W ebControls.Butt onColumn
              > >
              > > dcolumn.ButtonT ype = ButtonColumnTyp e.LinkButton
              > >
              > > dcolumn.DataTex tField = field_name
              > >
              > > dcolumn.HeaderT ext = field_name
              > >
              > > dcolumn.Command Name = "Select"
              > >
              > > dcolumn.Text = "Select"
              > >
              > > If field_name = "Company" Then mysql = "Select * from tblCompanys"
              > >
              > > If field_name = "Contact" Then mysql = "Select * from tblContacts"
              > >
              > > daAccounts = New SqlClient.SqlDa taAdapter(mysql , mycn)
              > >
              > > daAccounts.Fill (dsAccounts)
              > >
              > > DataGrid1.DataS ource = dsAccounts
              > >
              > > DataGrid1.DataK eyField = "ID"
              > >
              > > DataGrid1.Colum ns.Add(dcolumn)
              > >
              > > DataGrid1.DataB ind()
              > >
              > > mycn.Close()
              > >
              > > End Sub
              > >
              > >
              > >
              > >
              > >
              > >
              > > "Kairi Zikpin" <zikkai.nospam. @netscape.net> wrote in message
              > > news:YST1b.8226 46$3C2.18622897 @news3.calgary. shaw.ca...
              > >[color=darkred]
              > >>to answer your other question, viewstate is restored during page_init
              > >>which happens before page_load.
              > >>
              > >>also, i think the real problem you are having is where to put your code.
              > >>do not take action on postback in the page_lod event (in this case).
              > >>instead, take action in the bottun's click event since you are
              > >>responding to the click event.
              > >>
              > >>i'd encourage you to do some reading on event handlers. a good start
              > >>would be the following link (in internet explorer) provided you have the
              > >>visual studio.net documentation installed:
              > >>
              > >>[/color]
              > >
              > >[/color][/color]
              ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWebFormsPa geProcessingSta ges.htm[color=blue][color=green]
              > >[color=darkred]
              > >>Jim Mitchell wrote:
              > >>
              > >>
              > >>>Am I correct to assume that any changes to a control's properties or[/color]
              > >
              > > changes
              > >[color=darkred]
              > >>>to a ViewState("Name ") are not available until after the Page_Load[/color]
              > >
              > > fires?
              > >[color=darkred]
              > >>>If so, how can you set a flag in a control event so that you can take[/color]
              > >
              > > action
              > >[color=darkred]
              > >>>on postback?
              > >>>
              > >>>I have the following code..... The window.alert always reads 0
              > >>>
              > >>>
              > >>>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
              > >>>System.Event Args) Handles MyBase.Load
              > >>>
              > >>>'Put user code to initialize the page here
              > >>>
              > >>>If not ispostback then
              > >>>
              > >>> textbox1.text = 0
              > >>>
              > >>>end if
              > >>>
              > >>>Response.Wri te("<script language=javasc ript>window.ale rt('textbox1 = "[/color][/color][/color]
              &[color=blue][color=green][color=darkred]
              > >>>TextBox1.Tex t & "')</script>")
              > >>>
              > >>>End Sub
              > >>>
              > >>>
              > >>>Private Sub button1_Click(B yVal sender As System.Object, ByVal e As
              > >>>System.Event Args) Handles btnBindContacts .Click
              > >>>
              > >>>TextBox1.Tex t = 1
              > >>>
              > >>>ViewState("C allType") = 1
              > >>>
              > >>>End Sub
              > >>>
              > >>>
              > >>[/color]
              > >
              > >[/color]
              >[/color]


              Comment

              • Jim Mitchell

                #8
                Re: Sending data with post back.

                Thanks for your patience with me. I think you are on to something. When
                things get crazy, try deleting the datagrid and adding a fresh copy. It
                certainly seemed to work in this case.

                Jim

                "Kairi Zikpin" <zikkai.nospam. @netscape.net> wrote in message
                news:MKx2b.3536 2$la.493165@new s1.calgary.shaw .ca...[color=blue]
                > i tried your scenario and it works for me (only one column is shown of
                > course). since your datagrid has no design time configuration, i'd
                > suggest you delete it and create a new one. that saved me lots of
                > headaches in the past.
                >
                > Jim Mitchell wrote:[color=green]
                > > The bindgrid routine adds the columns at run time from the btn click[/color][/color]
                event.[color=blue][color=green]
                > >
                > > Jim
                > >
                > >
                > > "Kairi Zikpin" <zikkai.nospam. @netscape.net> wrote in message
                > > news:9R72b.1566 3$la.282727@new s1.calgary.shaw .ca...
                > >[color=darkred]
                > >>i just did this with no columns defined at run time and it works.
                > >>however i have autogenerate turned on. i don't see anywhere in your code
                > >>that you generate the columns, so if you turn off autogenerate, how do
                > >>you expect columns to show up?
                > >>
                > >>Jim Mitchell wrote:
                > >>
                > >>>Thank you for the very detailed answer. I guess I was trying to force
                > >>>something to happen in the page_load event chasing a challenge I have[/color]
                > >
                > > posted
                > >[color=darkred]
                > >>>in the Datagrid forum. Nevertheless, your answer reconfirmed the way I
                > >>>thought it should be happening. I will take your suggestion on the[/color]
                > >
                > > event
                > >[color=darkred]
                > >>>reading. If you think you might be able to help, I am taking action in[/color]
                > >
                > > the
                > >[color=darkred]
                > >>>button_cli ck event as shown below, but when I load a column in a[/color]
                > >
                > > datagrid at
                > >[color=darkred]
                > >>>run time with no columns at design time (and no autogenerate columns),[/color]
                > >
                > > my
                > >[color=darkred]
                > >>>datagrid dissappears on postback.
                > >>>
                > >>>Everyone was saying to "make sure you bind the datagrid on postback"[/color][/color][/color]
                and[color=blue][color=green][color=darkred]
                > >>>since binding in the button_click was not working, I kept trying to put[/color]
                > >
                > > it
                > >[color=darkred]
                > >>>in the load page event. The code below works perfectly if I have even[/color]
                > >
                > > one
                > >[color=darkred]
                > >>>column defined at design time, but as soon as I take all columns out at
                > >>>design time, everything falls apart.
                > >>>
                > >>>Thanks again for your help. Maybe you can catch something below that[/color][/color][/color]
                we[color=blue][color=green]
                > >
                > > are
                > >[color=darkred]
                > >>>missing.
                > >>>
                > >>>Jim
                > >>>
                > >>>
                > >>>
                > >>>
                > >>>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
                > >>>System.Event Args) Handles MyBase.Load
                > >>> If Not IsPostBack Then
                > >>> BindGrid("Compa ny")
                > >>> End If
                > >>>End Sub
                > >>>
                > >>>Private Sub btnFillOne_Clic k(ByVal sender As System.Object, ByVal e As
                > >>>System.Event Args) Handles btnFillOne.Clic k
                > >>>
                > >>> BindGrid("Compa ny")
                > >>>
                > >>>End Sub
                > >>>
                > >>>
                > >>>Private Sub btnFillTwo_Clic k(ByVal sender As System.Object, ByVal e As
                > >>>System.Event Args) Handles btnFillTwo.Clic k
                > >>>
                > >>> BindGrid("Conta ct")
                > >>>
                > >>>End Sub
                > >>>
                > >>>Sub BindGrid(ByVal field_name)
                > >>>
                > >>> Dim mycn As SqlClient.SqlCo nnection
                > >>>
                > >>> Dim daAccounts As SqlClient.SqlDa taAdapter
                > >>>
                > >>> Dim dsAccounts As New DataSet
                > >>>
                > >>> Dim mysql As String
                > >>>
                > >>> mycn = New
                > >>>[/color]
                > >
                > >[/color][/color]
                SqlClient.SqlCo nnection(System .Configuration. ConfigurationSe ttings.AppSetti n[color=blue][color=green]
                > >[color=darkred]
                > >>>gs("ConnectS tring"))
                > >>>
                > >>> DataGrid1.Colum ns.Clear()
                > >>>
                > >>> Dim dcolumn As System.Web.UI.W ebControls.Butt onColumn
                > >>>
                > >>> dcolumn = New System.Web.UI.W ebControls.Butt onColumn
                > >>>
                > >>> dcolumn.ButtonT ype = ButtonColumnTyp e.LinkButton
                > >>>
                > >>> dcolumn.DataTex tField = field_name
                > >>>
                > >>> dcolumn.HeaderT ext = field_name
                > >>>
                > >>> dcolumn.Command Name = "Select"
                > >>>
                > >>> dcolumn.Text = "Select"
                > >>>
                > >>> If field_name = "Company" Then mysql = "Select * from tblCompanys"
                > >>>
                > >>> If field_name = "Contact" Then mysql = "Select * from tblContacts"
                > >>>
                > >>> daAccounts = New SqlClient.SqlDa taAdapter(mysql , mycn)
                > >>>
                > >>> daAccounts.Fill (dsAccounts)
                > >>>
                > >>> DataGrid1.DataS ource = dsAccounts
                > >>>
                > >>> DataGrid1.DataK eyField = "ID"
                > >>>
                > >>> DataGrid1.Colum ns.Add(dcolumn)
                > >>>
                > >>> DataGrid1.DataB ind()
                > >>>
                > >>> mycn.Close()
                > >>>
                > >>>End Sub
                > >>>
                > >>>
                > >>>
                > >>>
                > >>>
                > >>>
                > >>>"Kairi Zikpin" <zikkai.nospam. @netscape.net> wrote in message
                > >>>news:YST1b.8 22646$3C2.18622 897@news3.calga ry.shaw.ca...
                > >>>
                > >>>
                > >>>>to answer your other question, viewstate is restored during page_init
                > >>>>which happens before page_load.
                > >>>>
                > >>>>also, i think the real problem you are having is where to put your[/color][/color][/color]
                code.[color=blue][color=green][color=darkred]
                > >>>>do not take action on postback in the page_lod event (in this case).
                > >>>>instead, take action in the bottun's click event since you are
                > >>>>respondin g to the click event.
                > >>>>
                > >>>>i'd encourage you to do some reading on event handlers. a good start
                > >>>>would be the following link (in internet explorer) provided you have[/color][/color][/color]
                the[color=blue][color=green][color=darkred]
                > >>>>visual studio.net documentation installed:
                > >>>>
                > >>>>
                > >>>
                > >>>[/color]
                > >[/color][/color]
                ms-help://MS.VSCC/MS.MSDNVS/vbcon/html/vbconWebFormsPa geProcessingSta ges.htm[color=blue][color=green]
                > >[color=darkred]
                > >>>>Jim Mitchell wrote:
                > >>>>
                > >>>>
                > >>>>
                > >>>>>Am I correct to assume that any changes to a control's properties or
                > >>>
                > >>>changes
                > >>>
                > >>>
                > >>>>>to a ViewState("Name ") are not available until after the Page_Load
                > >>>
                > >>>fires?
                > >>>
                > >>>
                > >>>>>If so, how can you set a flag in a control event so that you can take
                > >>>
                > >>>action
                > >>>
                > >>>
                > >>>>>on postback?
                > >>>>>
                > >>>>>I have the following code..... The window.alert always reads 0
                > >>>>>
                > >>>>>
                > >>>>>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
                > >>>>>System.Eve ntArgs) Handles MyBase.Load
                > >>>>>
                > >>>>>'Put user code to initialize the page here
                > >>>>>
                > >>>>>If not ispostback then
                > >>>>>
                > >>>>> textbox1.text = 0
                > >>>>>
                > >>>>>end if
                > >>>>>
                > >>>>>Response.W rite("<script language=javasc ript>window.ale rt('textbox1 =[/color][/color][/color]
                "[color=blue][color=green]
                > >
                > > &
                > >[color=darkred]
                > >>>>>TextBox1.T ext & "')</script>")
                > >>>>>
                > >>>>>End Sub
                > >>>>>
                > >>>>>
                > >>>>>Private Sub button1_Click(B yVal sender As System.Object, ByVal e As
                > >>>>>System.Eve ntArgs) Handles btnBindContacts .Click
                > >>>>>
                > >>>>>TextBox1.T ext = 1
                > >>>>>
                > >>>>>ViewState( "CallType") = 1
                > >>>>>
                > >>>>>End Sub
                > >>>>>
                > >>>>>
                > >>>>
                > >>>[/color]
                > >
                > >[/color]
                >[/color]


                Comment

                Working...