Asp.net DropDownList, AutoPostBack, and ViewState

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

    #1

    Asp.net DropDownList, AutoPostBack, and ViewState

    I'm trying to finish off do an ASP.NET project where a DropDownList box is
    used to access a Table.
    Once you Make a selection on an item in the DropDownListBox , it updates a
    DataView, and text boxes on the form get updated.

    I'd like to do this without a submit button.

    Shouldn't the DropDownList box PostBack?
    Why does SelectedIndexCh anged never get hit?
    Does the answer lie within ViewState?

    Any Info will help...

    Thanks.


  • Cor Ligthert

    #2
    Re: Asp.net DropDownList, AutoPostBack, and ViewState

    Corey,

    Only the button has his autopostback standard set too true. For the other
    controls you have to set that in the properties.

    I hope this helps,

    Cor


    Comment

    • Corey

      #3
      Re: Asp.net DropDownList, AutoPostBack, and ViewState

      Thanks Cor.

      I made the change to the text boxes. Unfortunately there's no change,
      except now when I type in them i get an Javascript Error In Internet
      Explorer which says

      Error: Object expected

      I think I know what is causing this. It's a parameter for a dataset, which
      is missing.

      But what i noticed with the DropDownList is when I changed it, I get a
      javascript error for it too.
      It says

      Line: 1
      Char: 1
      Error: 'WebForm_PostBa ckOptions' is undefined
      Code: 0

      Does This Help at all? I've searched google and came up with very little.

      Thanks.

      "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
      news:%23o4eIR5K FHA.3336@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > Corey,
      >
      > Only the button has his autopostback standard set too true. For the other
      > controls you have to set that in the properties.
      >
      > I hope this helps,
      >
      > Cor
      >[/color]


      Comment

      • Cor Ligthert

        #4
        Re: Asp.net DropDownList, AutoPostBack, and ViewState

        Corey,
        [color=blue]
        > I made the change to the text boxes.[/color]

        You said dropdownlist, that is the only place you should set the
        autopostback to true in my opinion.

        Cor


        Comment

        • Corey

          #5
          Re: Asp.net DropDownList, AutoPostBack, and ViewState

          Yeah, I removed it from the text boxes before.

          Any clues on my Javascript error?


          "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
          news:eBpOK05KFH A.3336@TK2MSFTN GP09.phx.gbl...[color=blue]
          > Corey,
          >[color=green]
          >> I made the change to the text boxes.[/color]
          >
          > You said dropdownlist, that is the only place you should set the
          > autopostback to true in my opinion.
          >
          > Cor
          >[/color]


          Comment

          • Cor Ligthert

            #6
            Re: Asp.net DropDownList, AutoPostBack, and ViewState

            Corey,

            Can you show by a little piece how you did your code, it is ASPNET and for
            that are three possibilities.

            Cor


            Comment

            • Corey

              #7
              Re: Asp.net DropDownList, AutoPostBack, and ViewState

              Here's My Code

              <form id="Form1" method="post" runat="server">

              <asp:textbox id=txtFirstName style="Z-INDEX: 101; LEFT: 33px; POSITION:
              absolute; TOP: 56px" runat="server" Width="235px" Height="23px" Text='<%#
              DataBinder.Eval (dvUsers1, "[0].FirstName", "{0}") %>'>

              </asp:textbox><as p:textbox id=txtLastName style="Z-INDEX: 102; LEFT:
              34px; POSITION: absolute; TOP: 99px" runat="server" Width="235px"
              Height="24px" Text='<%# DataBinder.Eval (dvUsers1, "[0].LastName", "{0}")
              %>'></asp:textbox><as p:datagrid id=DataGrid1 style="Z-INDEX: 103; LEFT:
              323px; POSITION: absolute; TOP: -48px" runat="server" Width="386px"
              Height="137px" Visible="False" DataMember="Use rs" DataKeyField="U serKey"
              DataSource='<%# DataBinder.Eval (DsUsers1, "Tables[Users]") %>'>

              </asp:datagrid><a sp:dropdownlist id=DropDownList 1 style="Z-INDEX: 104;
              LEFT: 36px; POSITION: absolute; TOP: 20px" runat="server" Width="227px"
              Height="27px" DataMember="Use rs" DataSource="<%# DsUsers1 %>"
              DataValueField= "UserKey" EnableViewState ="True" AutoPostBack="T rue"
              DataTextField=" UserID">

              </asp:dropdownlis t><asp:datagri d id=DataGrid2 style="Z-INDEX: 105; LEFT:
              34px; POSITION: absolute; TOP: 135px" runat="server"
              DataMember="sp_ RulesLookup" DataKeyField="r uledescr" DataSource="<%#
              DsRulesLookup1 %>" AutoGenerateCol umns="False">
              <Columns>
              <asp:BoundColum n DataField="rule descr" SortExpression= "ruledescr"
              HeaderText="Rul es"></asp:BoundColumn >
              </Columns>
              </asp:datagrid><a sp:button id="Button1" style="Z-INDEX: 106; LEFT: 321px;
              POSITION: absolute; TOP: 99px" runat="server" Width="250px" Height="28px"
              Text="Save Changes"></asp:button><asp :button id="Button2" style="Z-INDEX:
              107; LEFT: 324px; POSITION: absolute; TOP: 141px" runat="server"
              Width="253px" Height="28px" Text="Button"></asp:button></form>


              "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
              news:e627rq6KFH A.1156@TK2MSFTN GP09.phx.gbl...[color=blue]
              > Corey,
              >
              > Can you show by a little piece how you did your code, it is ASPNET and for
              > that are three possibilities.
              >
              > Cor
              >[/color]


              Comment

              • Cor Ligthert

                #8
                Re: Asp.net DropDownList, AutoPostBack, and ViewState

                Corey,

                This is the mainly RAD created part of your code.
                I don't know if you have any VBcode so called code behind.

                The problem with this is that I cannot simulate what you did, because it
                depends on your evironment that you draged on your form.

                However there must be as well a part wherin is that event from the
                dropdownlist.

                Cor


                Comment

                • Alvin Bruney [ASP.NET MVP]

                  #9
                  Re: Asp.net DropDownList, AutoPostBack, and ViewState

                  Why is the Xposted all over the place?

                  --
                  Regards,
                  Alvin Bruney
                  [Shameless Author Plug]
                  The Microsoft Office Web Components Black Book with .NET
                  available at www.lulu.com/owc
                  _______________ __________


                  "Corey" <shadowcaster@r ogers.com> wrote in message
                  news:uju_d.6946 5$Jd2.1368800@n ews20.bellgloba l.com...[color=blue]
                  > I'm trying to finish off do an ASP.NET project where a DropDownList box is
                  > used to access a Table.
                  > Once you Make a selection on an item in the DropDownListBox , it updates a
                  > DataView, and text boxes on the form get updated.
                  >
                  > I'd like to do this without a submit button.
                  >
                  > Shouldn't the DropDownList box PostBack?
                  > Why does SelectedIndexCh anged never get hit?
                  > Does the answer lie within ViewState?
                  >
                  > Any Info will help...
                  >
                  > Thanks.
                  >[/color]


                  Comment

                  • Corey

                    #10
                    Re: Asp.net DropDownList, AutoPostBack, and ViewState

                    Any time i try to change the DropDownList I get a javascript error which
                    says "Error: 'WebForm_PostBa ckOptions' is undefined"
                    How can I restore this?

                    VB Code is as follows.


                    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

                    SqlDAUsers.Fill (DsUsers1)

                    DropDownList1.D ataBind()

                    ' DataGrid1.DataB ind()

                    ' dvUsers1.RowFil ter = "Userkey = " & Me.ViewState("D ropDownList1") '&
                    DsUsers1.Users. UserKeyColumn.T oString()

                    txtFirstName.Da taBind()

                    txtLastName.Dat aBind()

                    SqlDARulesLooku p.SelectCommand .Parameters.Ite m(1).Value =
                    DropDownList1.S electedItem.Val ue

                    SqlDARulesLooku p.Fill(DsRulesL ookup1)

                    DataGrid2.DataB ind()

                    End If

                    ' Response.Write( "Selected - " + DropDownList1.S electedItem.Val ue)

                    ' Response.Write( "Uber Select - " & DropDownList1.S electedIndex)

                    End Sub

                    Private Sub DropDownList1_S electedIndexCha nged(ByVal sender As
                    System.Object, ByVal e As System.EventArg s) Handles
                    DropDownList1.S electedIndexCha nged



                    ' txtFirstName.Te xt = DsUsers1.Users. FirstNameColumn .ToString

                    ' txtLastName.Tex t = DsUsers1.Users. LastNameColumn. ToString

                    dvUsers1.RowFil ter = "Userkey = " & DsUsers1.Users. UserKeyColumn.T oString()

                    txtFirstName.Da taBind()

                    txtLastName.Dat aBind()

                    Response.Write( "SelectedIndex! ")

                    End Sub

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

                    Dim strSQLQuery As String

                    strSQLQuery = "UPDATE Users " _

                    & "SET FirstName = '" & Replace(txtFirs tName.Text, "'", "''") & "', " _

                    & "LastName = '" & Replace(txtLast Name.Text, "'", "''") & "' " _

                    & "WHERE UserKey = " & DropDownList1.S electedItem.Val ue & ";"

                    'Response.Write (strSQLQuery)

                    SqlSaveCommand. CommandText = strSQLQuery

                    SqlUsers.Open()

                    SqlSaveCommand. ExecuteNonQuery ()

                    SqlUsers.Close( )

                    'update datasets?

                    End Sub

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

                    ' Define Crystal Reports variables

                    Dim crReportDocumen t As ReportDocument

                    Dim crExportOptions As ExportOptions

                    Dim crDiskFileDesti nationOptions As DiskFileDestina tionOptions

                    Dim Fname As String

                    ' The following code can be placed directly after the call to

                    ' InitializeCompo nent() in the form's constructor, or inside of

                    ' a Button_Click event where the button is used by the client to

                    ' get a printable copy of the report.

                    crReportDocumen t = New ReportDocument( )

                    ' The following line of code loads the sample report "Chart.rpt" that
                    installs

                    ' with Visual Studio .NET

                    crReportDocumen t.Load("C:\Inet pub\wwwroot\Web Application3\Cr ystalReport2.rp t")

                    Fname = "C:\inetpub\www root\WebApplica tion3\" & Session.Session ID.ToString &
                    ".pdf"

                    crDiskFileDesti nationOptions = New DiskFileDestina tionOptions()

                    crDiskFileDesti nationOptions.D iskFileName = Fname

                    crExportOptions = crReportDocumen t.ExportOptions

                    With crExportOptions

                    ..DestinationOp tions = crDiskFileDesti nationOptions

                    ..ExportDestina tionType = ExportDestinati onType.DiskFile

                    ..ExportFormatT ype = ExportFormatTyp e.PortableDocFo rmat

                    End With

                    crReportDocumen t.Refresh()

                    crReportDocumen t.Export()

                    ' The following code writes the pdf file to the Client's browser.

                    Response.ClearC ontent()

                    Response.ClearH eaders()

                    Response.Conten tType = "applicatio n/pdf"

                    Response.WriteF ile(Fname)

                    Response.Flush( )

                    Response.Close( )

                    'delete the exported file from disk

                    System.IO.File. Delete(Fname)

                    End Sub

                    End Class


                    "Cor Ligthert" <notmyfirstname @planet.nl> wrote in message
                    news:OEpRyQ$KFH A.2860@TK2MSFTN GP10.phx.gbl...[color=blue]
                    > Corey,
                    >
                    > This is the mainly RAD created part of your code.
                    > I don't know if you have any VBcode so called code behind.
                    >
                    > The problem with this is that I cannot simulate what you did, because it
                    > depends on your evironment that you draged on your form.
                    >
                    > However there must be as well a part wherin is that event from the
                    > dropdownlist.
                    >
                    > Cor
                    >[/color]


                    Comment

                    • Corey

                      #11
                      Re: Asp.net DropDownList, AutoPostBack, and ViewState

                      Visual Studio must have put them in.

                      "Alvin Bruney [ASP.NET MVP]" <www.lulu.com/owc> wrote in message
                      news:%23SxOQYBL FHA.3296@TK2MSF TNGP15.phx.gbl. ..[color=blue]
                      > Why is the Xposted all over the place?
                      >
                      > --
                      > Regards,
                      > Alvin Bruney
                      > [Shameless Author Plug]
                      > The Microsoft Office Web Components Black Book with .NET
                      > available at www.lulu.com/owc
                      > _______________ __________
                      >
                      >
                      > "Corey" <shadowcaster@r ogers.com> wrote in message
                      > news:uju_d.6946 5$Jd2.1368800@n ews20.bellgloba l.com...[color=green]
                      >> I'm trying to finish off do an ASP.NET project where a DropDownList box
                      >> is used to access a Table.
                      >> Once you Make a selection on an item in the DropDownListBox , it updates a
                      >> DataView, and text boxes on the form get updated.
                      >>
                      >> I'd like to do this without a submit button.
                      >>
                      >> Shouldn't the DropDownList box PostBack?
                      >> Why does SelectedIndexCh anged never get hit?
                      >> Does the answer lie within ViewState?
                      >>
                      >> Any Info will help...
                      >>
                      >> Thanks.
                      >>[/color]
                      >
                      >[/color]


                      Comment

                      • Cor Ligthert

                        #12
                        Re: Asp.net DropDownList, AutoPostBack, and ViewState

                        Answered in the follow up thread


                        Comment

                        Working...