473,721 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList in usercontrol does not display new value

I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit is performed.

How do I force the usercontrol to display the newly assigned date? I don't have this problem if I place the two dropdownlist and the year field directly on the aspx page.
Nov 18 '05 #1
2 3118
On Thu, 10 Jun 2004 03:13:01 -0700, Benedict Teoh <Benedict
Te**@discussion s.microsoft.com> wrote:
I created a dropdownlist containing day, month and year field and expose
a property to assign a date. When I call from a aspx page and assign
the value, the new date is not displayed until a submit is performed.

How do I force the usercontrol to display the newly assigned date? I
don't have this problem if I place the two dropdownlist and the year
field directly on the aspx page.


Need a little more info on this...when you say '...I call from a aspx page
and assign
the value, the new date is not displayed', can you explain the whole
scenario. From initial loading of the page the first time up to your
problem? Also, a little code snippet may help debug....

if you're still having problems...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2
this is the control and the code behind:

<%@ Control Language="vb" AutoEventWireup ="false" Codebehind="cal .ascx.vb" Inherits="SHO.c al" TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<asp:dropdownli st id="Dy" Width="40px" runat="server"> </asp:dropdownlis t><asp:dropdown list id="Mth" runat="server"> </asp:dropdownlis t><asp:textbox id="Yr" Width="35px" runat="server"> </asp:textbox><as p:label id="valDate" runat="server" CssClass="errMs g"></asp:label>

=============

Public Class cal
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
Protected WithEvents Dy As System.Web.UI.W ebControls.Drop DownList
Protected WithEvents Mth As System.Web.UI.W ebControls.Drop DownList
Protected WithEvents Yr As System.Web.UI.W ebControls.Text Box
Protected WithEvents valDate As System.Web.UI.W ebControls.Labe l

'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
Dim loopcnt As Integer

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
Dim loopCnt As Int16
Dim tmpStr As String
'If Dy.Items.Count = 0 Then
' filldate()
'End If

'valDate.Text = ""
If Not IsPostBack Then
filldate()
'Dy.SelectedInd ex = Day(Now()) - 1
'Mth.SelectedIn dex = Month(Now()) - 1
'Yr.Text = Year(Now())
'selcal = Now()
Else
Try
tmpStr = Date.Parse(Dy.S electedValue & "-" & Mth.SelectedVal ue & "-" & Yr.Text)
'valDate.Text = "Valid"
Catch ex As Exception
valDate.Text += "<br>Invali d Date"
End Try

End If
End Sub

Private Sub filldate()
For loopCnt = 1 To 31
Dy.Items.Add(Fo rmat(New DateTime(Year(N ow()), 1, loopcnt), "dd"))
Next
For loopCnt = 1 To 12
Mth.Items.Add(F ormat(New DateTime(Year(N ow()), loopCnt, 1), "MMM"))
Next
Yr.Text = Year(Now())

End Sub

Public Function IsValid() As Boolean
If valDate.Text = "Valid" Then
IsValid = True
Else
IsValid = False
End If
End Function

Public Property selcal() As Date
Get
Try
valDate.Text += "<br>seldy is " & Dy.SelectedValu e
valDate.Text += "<br>get val is " & Dy.SelectedValu e & "-" & Mth.SelectedVal ue & "-" & Yr.Text
selcal = Date.Parse(Dy.S electedValue & "-" & Mth.SelectedVal ue & "-" & Yr.Text)
'valDate.Text = "Valid"
Catch ex As Exception
valDate.Text += "<br>Invali d Date"
'selcal = Nothing
End Try
End Get
Set(ByVal Value As Date)
Dy.SelectedValu e = Format(Value, "dd")
valDate.Text += "<br>dy is " & Format(Value, "dd")
Mth.SelectedVal ue = Format(Value, "MMM")
valDate.Text += "<br>Mth value is " & Format(Value, "MMM")
Yr.Text = Format(Value, "yyyy")
valDate.Text += "<br>yr val is " & Format(Value, "yyyy")
'Response.Write ("<br>value is " & Value)
End Set
End Property

'Public Sub setCal(ByVal pDate As Date)
' Dy.SelectedValu e = Format(pDate, "dd")
' Mth.SelectedVal ue = Format(pDate, "MMM")
' Yr.Text = Format(pDate, "yyyy")
' 'Response.Write ("<br>value is " & Value)
'End Sub

Public Property enable() As Boolean
Get

End Get
Set(ByVal Value As Boolean)
If Not Value Then
Dy.Enabled = False
Mth.Enabled = False
Yr.Enabled = False
Else
Dy.Enabled = True
Mth.Enabled = True
Yr.Enabled = True
End If
End Set
End Property

End Class

=============== =

This is the aspx and the code behind calling the code:

<%@ Register TagPrefix="uc1" TagName="cal" Src="includes/cal.ascx" %>
<%@ Register TagPrefix="uc1" TagName="FullRe lJust" Src="UserContro l/FullRelJust.asc x" %>
<%@ Page Language="vb" AutoEventWireup ="false" Codebehind="tes tDateform.aspx. vb" Inherits="SHO.t estDateform"%>
<%@ Register TagPrefix="uc1" TagName="CalCtr l" Src="UserContro l/CalCtrl.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>testDate form</title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema" content="http://schemas.microso ft.com/intellisense/ie5">
<LINK href="styleshee ts/SHO2.css" type="text/css" rel="stylesheet ">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<P>
<uc1:cal id="Cal1" runat="server"> </uc1:cal></P>
<P>
<asp:DropDownLi st id="tDy" runat="server">
<asp:ListItem Value="01">01</asp:ListItem>
<asp:ListItem Value="02">02</asp:ListItem>
<asp:ListItem Value="03">03</asp:ListItem>
</asp:DropDownLis t></P>
<P>
<asp:Button id="Submit" runat="server" Text="Submit"></asp:Button></P>
<P>
<asp:Label id="msg" runat="server"> </asp:Label></P>
</form>
</body>
</HTML>
=============

Public Class testDateform
Inherits System.Web.UI.P age

#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
Protected WithEvents msg As System.Web.UI.W ebControls.Labe l
Protected WithEvents Submit As System.Web.UI.W ebControls.Butt on
Protected WithEvents tDy 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

Protected WithEvents cal1 As cal

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
Dim tmpDate As Date

msg.Text = ""

tmpDate = Date.Parse("20-dec-2003")

If Not IsPostBack Then
cal1.selcal = tmpDate
'CalCtrl1.selDa te = tmpDate
'FullRelJust1.c Date1 = tmpDate
tDy.SelectedVal ue = "02"
Else
msg.Text += "<br>cal1 is " & Format(cal1.sel cal, "dd-MMM-yyyy")
cal1.selcal = tmpDate
End If

msg.Text += "<br>selcal done"
msg.Text += "<br>setcal done"
msg.Text += "<br>tmpdat e is " & Format(tmpDate, "dd-MMM-yyyy")

'msg.Text += "<br>fullreljus t1 cal1 is " & Format(FullRelJ ust1.cDate1, "dd-MMM-yyyy")

End Sub

End Class

==============
As you can see I assign a value via the selcal property but the value does not get updated until I click the submit button to postback the form.

Need a little more info on this...when you say '...I call from a aspx page
and assign
the value, the new date is not displayed', can you explain the whole
scenario. From initial loading of the page the first time up to your
problem? Also, a little code snippet may help debug....

if you're still having problems...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET

Nov 18 '05 #3

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

Similar topics

1
6561
by: Liz | last post by:
I have a page with several dropdownlists, several text boxes and several buttons which perform calculations. I need to validate one dropdownlist (not the whole page) with the click of one button. I have a separate submit button which should validate the other fields. This page on MSDN does what I want - almost! ...
1
2559
by: Joe | last post by:
Hello All: I have created a class (UpdatedDropDown) that inherits from DropDownList and I have included the following code in this class: Public Class UpdatedDropDown Inherits DropDownList Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter) For c As Integer = 0 To Items.Count - 1
12
2207
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control server. It "serves" back the required control (either WebControl or UserControl) based on the contents of an xml file. The code in the webform places each control in a TableCell. My problem is that the control server works as far as returning the...
2
2350
by: lotus | last post by:
HI All.. I'm realtively new to C#. I have MainForm which includes Parent usercontol, and this parent usercontrol also contains child usercontrol. MainForm --> Parent usercontrol --> child usercontrol Parent usercontol has one button to change the child usercontorl's variable.
2
2276
by: Michael | last post by:
Hi again, I really hope that there is a simple solution to this one, cause I'm having simular things happening to other controls on this usercontrol. I have the following control: <asp:DropDownList ID="cmbOptions" runat="server" Width="195px"> <asp:ListItem Text="Search by PO ID" Value=0 Selected="True" /> <asp:ListItem Text="Search by Field" Value=1 /> <asp:ListItem Text="Search between dates" Value=2 /> <asp:ListItem Text="Search Most...
1
2029
by: DJ | last post by:
I have a DropDownList in Visual Web Developer that is databound to a SQL Database. Whenever the web page is opened the DropDownList is automatically filled with the first item in the table. My question is, how do I set it so that the DropDownList is empty until a value is selected?
2
1625
by: OJ | last post by:
Hi, ASP.NET C# 2.0 I have a usercontrol which contains a Gridview. I create my own DataTable to bind to the GridView, which then fires the RowDataBound event of the the Gridview. Here I add a dropdownlist to the relevent row.Cell. I then expose the GridView as a public property of the usercontrol. This all works lovely. However, when I try to find the dropdownlist by accessing the GridView property of the usercontrol on the ASP next...
1
1124
by: pichukakiran | last post by:
Hai, Here I am using a dropdownlist in a usercontrol.in that i am using some numbers like 5,10,15,20 like that. Coming to my aspx page.In that i am using a gridview and i added that usercontrol to my page.I have to assign the dropdown value from usercontrol to my gridview page index.whenever i changed the value of the dropdown the gridview pagination should change based on the dropdown value. I have taken a dropdown in my page and i...
0
1774
by: stevem2112 | last post by:
I have a datagrid with 2 Template columns. One column has DropDownLists and the other has Textboxes. I bind each DDL in the ItemCreated event. This datagrid is inside a UserControl that is inside a user control (long story). Anyway, the user clicks a save button on the parent control to initiate the postback. The parent then calls a Save method (in the child control) from the button event handler. When I iterate through the datagrid...
0
8860
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9234
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9086
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8028
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6678
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5994
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4501
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3207
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

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.