473,547 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SelectedIndex is not submitted with post

I am working on a simple user control composed of 3 DropDownLists that will be used to select Dates. The purpose of the control is to all the user to choose a date using dropdown lists but not need to worry about choosing a non-existing date (due to different months having different numbers of days). They all have AutoPostBack="T rue", but when the eventhandler attempts to use the SelectedIndex property, it is always the same. Here is the code:
Public Class DatePicker
Inherits System.Web.UI.U serControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
End Sub
Private selectdate As Date = Date.Today
Private startyear As Integer = 1900
Private stopyear As Integer = 2100
Protected WithEvents ddlMonth As System.Web.UI.W ebControls.Drop DownList
Protected WithEvents ddlDate As System.Web.UI.W ebControls.Drop DownList
Protected WithEvents ddlYear As System.Web.UI.W ebControls.Drop DownList

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceho lderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
End Sub
#End Region

Public Property SelectedDate() As Date
Get
Return Me.selectdate
End Get
Set(ByVal Value As Date)
Me.selectdate = Value
Me.startyear = Math.Min(Me.sel ectdate.Year, Me.startyear)
Me.stopyear = Math.Max(Me.sel ectdate.Year, Me.stopyear)
Me.CreateLists( )
End Set
End Property
Public Property FirstYear() As Integer
Get
Return Me.startyear
End Get
Set(ByVal Value As Integer)
If Value <= Me.selectdate.Y ear AndAlso Value >= 1 Then
Me.startyear = Value
Me.CreateLists( )
End If
End Set
End Property
Public Property LastYear() As Integer
Get
Return Me.stopyear
End Get
Set(ByVal Value As Integer)
If Value >= Me.selectdate.Y ear AndAlso Value <= 9999 Then
Me.stopyear = Value
Me.CreateLists( )
End If
End Set
End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack() Then Me.CreateLists( )
End Sub

Private Sub CreateLists()
ddlMonth.Items. Clear()
ddlYear.Items.C lear()
ddlDate.Items.C lear()
For i As Integer = 1 To 12
ddlMonth.Items. Add(New ListItem(System .Globalization. DateTimeFormatI nfo.CurrentInfo .GetMonthName(i ), CStr(i)))
Next
For j As Integer = Me.startyear To Me.stopyear
ddlYear.Items.A dd(CStr(j))
Next
For i As Integer = 1 To Date.DaysInMont h(Me.selectdate .Year, Me.selectdate.M onth)
ddlDate.Items.A dd(New ListItem(CStr(i ) & " " & System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames (New Date(Me.selectd ate.Year, Me.selectdate.M onth, i).DayOfWeek), CStr(i)))
Next
ddlMonth.Select edIndex = Me.selectdate.M onth - 1
ddlYear.Selecte dIndex = Me.selectdate.Y ear - Me.startyear
ddlDate.Selecte dIndex = Me.selectdate.D ay - 1
End Sub

Private Sub DateChanged(ByV al sender As Object, ByVal e As System.EventArg s) Handles ddlMonth.Select edIndexChanged, ddlYear.Selecte dIndexChanged, ddlDate.Selecte dIndexChanged
Dim selectedday As Integer = ddlDate.Selecte dIndex + 1
ddlDate.Items.C lear()
For i As Integer = 1 To Date.DaysInMont h(ddlYear.Selec tedIndex + Me.startyear, ddlMonth.Select edIndex + 1)
ddlDate.Items.A dd(New ListItem(CStr(i ) & " " & System.Globaliz ation.DateTimeF ormatInfo.Curre ntInfo.DayNames (New Date(ddlYear.Se lectedIndex + Me.startyear, ddlMonth.Select edIndex + 1, i).DayOfWeek), CStr(i)))
Next
If Date.DaysInMont h(ddlYear.Selec tedIndex + Me.startyear, ddlMonth.Select edIndex + 1) >= selectedday Then
ddlDate.Selecte dIndex = selectedday - 1
Else
ddlDate.Selecte dIndex = Date.DaysInMont h(ddlYear.Selec tedIndex + Me.startyear, ddlMonth.Select edIndex + 1) - 1
End If
Me.selectdate = New Date(ddlYear.Se lectedIndex + Me.startyear, ddlMonth.Select edIndex + 1, ddlDate.Selecte dIndex + 1)
End Sub
End Class
<%@ Control Language="vb" AutoEventWireup ="false" Codebehind="Dat ePicker.ascx.vb " Inherits="WebAp plication1.Date Picker" TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<asp:dropdownli st id="ddlMonth" runat="server" AutoPostBack="T rue"></asp:dropdownlis t>
<asp:dropdownli st id="ddlDate" runat="server" AutoPostBack="T rue"></asp:dropdownlis t>
<asp:dropdownli st id="ddlYear" runat="server" AutoPostBack="T rue"></asp:dropdownlis t>

--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Nov 19 '05 #1
3 2390
<quote>
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:Oy******** ******@TK2MSFTN GP14.phx.gbl...
I am working on a simple user control composed of 3 DropDownLists that will
be used to select Dates. The purpose of the control is to all the user to
choose a date using dropdown lists but not need to worry about choosing a
non-existing date (due to different months having different numbers of
days). They all have AutoPostBack="T rue", but when the eventhandler attempts
to use the SelectedIndex property, it is always the same. Here is the code:
</quote>

I've copied your code into a test project and it worked fine (from what I
could tell). Where exactly is the SelectedIndex always the same? (in
DateChanged it seems to have correct values)

Nov 19 '05 #2
In the DateChanged method (the eventhandler for the DropDownLists'
SelectedIndexCh anged events). I have been looking at the Control more, and
the problem may be initially caused by the 3 variables declared at the top
(selectdate, startyear, and stopyear) being reset with each postback. I am
working on a second copy of this User Control to try and figure out this
problem (I posted another message titled "Value of variable in my user
control keeps getting reset" that describes this and shows the code for my
second copy). Although I have written many user controls that display data
before, I am relatively new to writing user controls that allow you to set
properties and that actually remember data.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Peter Zolja" <csu10711atmail .claytonstate.n et> wrote in message
news:OF******** ******@TK2MSFTN GP10.phx.gbl...
<quote>
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:Oy******** ******@TK2MSFTN GP14.phx.gbl...
I am working on a simple user control composed of 3 DropDownLists that
will be used to select Dates. The purpose of the control is to all the
user to choose a date using dropdown lists but not need to worry about
choosing a non-existing date (due to different months having different
numbers of days). They all have AutoPostBack="T rue", but when the
eventhandler attempts to use the SelectedIndex property, it is always the
same. Here is the code:
</quote>

I've copied your code into a test project and it worked fine (from what I
could tell). Where exactly is the SelectedIndex always the same? (in
DateChanged it seems to have correct values)

Nov 19 '05 #3
If it helps, I use ViewState to 'remember' data between postbacks. But be
wary of storing too much in it because the ViewState is sent to the client
in the page and then back to IIS on a postback.

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:ev******** ******@TK2MSFTN GP09.phx.gbl...
In the DateChanged method (the eventhandler for the DropDownLists'
SelectedIndexCh anged events). I have been looking at the Control more, and
the problem may be initially caused by the 3 variables declared at the top
(selectdate, startyear, and stopyear) being reset with each postback. I am
working on a second copy of this User Control to try and figure out this
problem (I posted another message titled "Value of variable in my user
control keeps getting reset" that describes this and shows the code for my
second copy). Although I have written many user controls that display data
before, I am relatively new to writing user controls that allow you to set
properties and that actually remember data.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

"Peter Zolja" <csu10711atmail .claytonstate.n et> wrote in message
news:OF******** ******@TK2MSFTN GP10.phx.gbl...
<quote>
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:Oy******** ******@TK2MSFTN GP14.phx.gbl...
I am working on a simple user control composed of 3 DropDownLists that
will be used to select Dates. The purpose of the control is to all the
user to choose a date using dropdown lists but not need to worry about
choosing a non-existing date (due to different months having different
numbers of days). They all have AutoPostBack="T rue", but when the
eventhandler attempts to use the SelectedIndex property, it is always the
same. Here is the code:
</quote>

I've copied your code into a test project and it worked fine (from what I
could tell). Where exactly is the SelectedIndex always the same? (in
DateChanged it seems to have correct values)


Nov 19 '05 #4

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

Similar topics

2
2175
by: Alexandre Jaquet | last post by:
Hi, Under IE I could not point why I can't get the selected value from a function here the code function Lvl_P2P(url,closeIt,delay){ //ver1.0 4LevelWebs var fabricant_box; var fabricant_value;
3
4663
by: Nikhil Patel | last post by:
Hi all, I am using the standard System.Windows.Forms.ComboBox controls on a form. There are 5 or 6 comboboxes and their selection depends on each other. The comboboxes behave strangely probably because there are two properties called SelectedIndex and selectedIndex. Both usually have different values. Has anyone experienced any problems using...
2
2271
by: Robert V. Hanson | last post by:
I have a user control built using the Microsoft IE Control. I declared a public variable as int32 (DefaultTab) in the user control. I can't seem to provide the correct syntax to the tabstrip property other than SelectedIndex = 1 which works but if I try SelectedIndex = DefaultTab, it fails stating that DefaultTab is not a valid value for...
5
3517
by: Lie | last post by:
Hi all, I have problem in getting selectedindex of multiple listbox selection in a datagrid. I have a listbox with multiple selection mode inside datagrid. In Edit mode, I need to get back all selected items of that listbox and display it. can anyone help? Thanks
3
1683
by: Angel | last post by:
I have a problem I placed a DropDown list control on my .NET page. I do not want to perform a postback when something is selected. When I want to get what was selected in the Client Script I do not get anything in the selectedIndex property in the client script. Is there any way for me the get the value in the text portion of the dropdown list...
12
5059
by: Steve Dyte | last post by:
Hi, I've narrowed down a problem I've been having filling a combobox with the results of a query stored in a datatable. I'm setting the ValueMember and DisplayMember to the relevant column names, and then I want to make sure nothing is selected. By default it appears that if you do nothing, the first item (0) is selected. However, I want...
3
1101
by: Nathan Sokalski | last post by:
I am working on a simple user control composed of 3 DropDownLists that will be used to select Dates. The purpose of the control is to all the user to choose a date using dropdown lists but not need to worry about choosing a non-existing date (due to different months having different numbers of days). They all have AutoPostBack="True", but when the...
7
7738
by: CFonville | last post by:
I have a script that is working fine in the latest version of Firefox with no errors or warnings, but does not work in IE. I have several select boxes that, when changed, update some text (a price) on the page. I'm checking what value is selected with an if statement, setting a variable, then later updating the page. Here's the code that...
0
2376
by: reddog | last post by:
Getting the SelectedIndex of a DropDownlist under the ItemTemplate in a GridView is harder than I thought it would be. I have: A Gridview of n rows bound to a DataSet. A DropDownList as an ItemTemplate in the GridView populated with three ListItems. A Button to Submit the form.
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7698
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7794
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3492
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.