473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 SelectedIndexChanged never get hit?
Does the answer lie within ViewState?

Any Info will help...

Thanks.
Nov 21 '05 #1
12 1315
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
Nov 21 '05 #2
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_PostBackOptions' is undefined
Code: 0

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

Thanks.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #3
Corey,
I made the change to the text boxes.


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

Cor
Nov 21 '05 #4
Yeah, I removed it from the text boxes before.

Any clues on my Javascript error?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:eB**************@TK2MSFTNGP09.phx.gbl...
Corey,
I made the change to the text boxes.


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

Cor

Nov 21 '05 #5
Corey,

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

Cor
Nov 21 '05 #6
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><asp: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><asp:datagrid id=DataGrid1 style="Z-INDEX: 103; LEFT:
323px; POSITION: absolute; TOP: -48px" runat="server" Width="386px"
Height="137px" Visible="False" DataMember="Users" DataKeyField="UserKey"
DataSource='<%# DataBinder.Eval(DsUsers1, "Tables[Users]") %>'>

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

</asp:dropdownlist><asp:datagrid id=DataGrid2 style="Z-INDEX: 105; LEFT:
34px; POSITION: absolute; TOP: 135px" runat="server"
DataMember="sp_RulesLookup" DataKeyField="ruledescr" DataSource="<%#
DsRulesLookup1 %>" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="ruledescr" SortExpression="ruledescr"
HeaderText="Rules"></asp:BoundColumn>
</Columns>
</asp:datagrid><asp: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" <no************@planet.nl> wrote in message
news:e6**************@TK2MSFTNGP09.phx.gbl...
Corey,

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

Cor

Nov 21 '05 #7
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
Nov 21 '05 #8
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" <sh**********@rogers.com> wrote in message
news:uj*********************@news20.bellglobal.com ...
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 SelectedIndexChanged never get hit?
Does the answer lie within ViewState?

Any Info will help...

Thanks.

Nov 21 '05 #9
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" <sh**********@rogers.com> wrote in message
news:uj*********************@news20.bellglobal.com ...
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 SelectedIndexChanged never get hit?
Does the answer lie within ViewState?

Any Info will help...

Thanks.

Nov 21 '05 #10
Any time i try to change the DropDownList I get a javascript error which
says "Error: 'WebForm_PostBackOptions' 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.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

SqlDAUsers.Fill(DsUsers1)

DropDownList1.DataBind()

' DataGrid1.DataBind()

' dvUsers1.RowFilter = "Userkey = " & Me.ViewState("DropDownList1") '&
DsUsers1.Users.UserKeyColumn.ToString()

txtFirstName.DataBind()

txtLastName.DataBind()

SqlDARulesLookup.SelectCommand.Parameters.Item(1). Value =
DropDownList1.SelectedItem.Value

SqlDARulesLookup.Fill(DsRulesLookup1)

DataGrid2.DataBind()

End If

' Response.Write("Selected - " + DropDownList1.SelectedItem.Value)

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

End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged

' txtFirstName.Text = DsUsers1.Users.FirstNameColumn.ToString

' txtLastName.Text = DsUsers1.Users.LastNameColumn.ToString

dvUsers1.RowFilter = "Userkey = " & DsUsers1.Users.UserKeyColumn.ToString()

txtFirstName.DataBind()

txtLastName.DataBind()

Response.Write("SelectedIndex!")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim strSQLQuery As String

strSQLQuery = "UPDATE Users " _

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

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

& "WHERE UserKey = " & DropDownList1.SelectedItem.Value & ";"

'Response.Write(strSQLQuery)

SqlSaveCommand.CommandText = strSQLQuery

SqlUsers.Open()

SqlSaveCommand.ExecuteNonQuery()

SqlUsers.Close()

'update datasets?

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

' Define Crystal Reports variables

Dim crReportDocument As ReportDocument

Dim crExportOptions As ExportOptions

Dim crDiskFileDestinationOptions As DiskFileDestinationOptions

Dim Fname As String

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

' InitializeComponent() 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.

crReportDocument = New ReportDocument()

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

' with Visual Studio .NET

crReportDocument.Load("C:\Inetpub\wwwroot\WebAppli cation3\CrystalReport2.rpt")

Fname = "C:\inetpub\wwwroot\WebApplication3\" & Session.SessionID.ToString &
".pdf"

crDiskFileDestinationOptions = New DiskFileDestinationOptions()

crDiskFileDestinationOptions.DiskFileName = Fname

crExportOptions = crReportDocument.ExportOptions

With crExportOptions

..DestinationOptions = crDiskFileDestinationOptions

..ExportDestinationType = ExportDestinationType.DiskFile

..ExportFormatType = ExportFormatType.PortableDocFormat

End With

crReportDocument.Refresh()

crReportDocument.Export()

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

Response.ClearContent()

Response.ClearHeaders()

Response.ContentType = "application/pdf"

Response.WriteFile(Fname)

Response.Flush()

Response.Close()

'delete the exported file from disk

System.IO.File.Delete(Fname)

End Sub

End Class
"Cor Ligthert" <no************@planet.nl> wrote in message
news:OE**************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #11
Visual Studio must have put them in.

"Alvin Bruney [ASP.NET MVP]" <www.lulu.com/owc> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
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" <sh**********@rogers.com> wrote in message
news:uj*********************@news20.bellglobal.com ...
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 SelectedIndexChanged never get hit?
Does the answer lie within ViewState?

Any Info will help...

Thanks.


Nov 21 '05 #12
Answered in the follow up thread
Nov 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second...
4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
4
by: sklett | last post by:
I have 2 dropdownlist on a page. They have ViewState = true. After I submit to the page, the selection in the DropDownList is lost. I set a break in the Page_Load event to make sure that I...
6
by: Roshawn | last post by:
Hi, I have a DDL server control on my web form. I'm having difficulty trying to fire the OnSelectedIndexChanged event. I've specified a procedure to handle the event. Whenever I changed the...
5
by: bryanp10 | last post by:
I have a page that is almost entirely dynamically created. Textboxes and checkbox are working fine, firing events, and persistent their state. DropDownList is giving me a major headache. All...
5
by: Victorious1 | last post by:
Why doesn't the the SelectedIndexchanged event for my dropdownlist ever get executed? Why do I get a page not found error when I select a new item? My dropdownlist is within a form. The items...
1
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.