473,698 Members | 2,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

returning values from dynamically created user control

Hi,

I've got a fairly simple date control, that I'm creating dynamically in my
page. The reason for creating it dynamically is that I want the ID to vary,
depending on it's situation.

The control loads on the page, and the set date is shown. The problem is,
when I submit the page, the control doesn't return the date. What am I
doing wrong?

Dunc

---/ snip /---

*** extract from default.aspx
' Dynamically create start date box
ctrlStartDate = Me.LoadControl( "~\UserControls \DateBox.ascx")
ctrlStartDate.C ontrolName = "StartDate"

' Add the dynamic controls to their appropriate panels on the page
pnlStartDate.Co ntrols.Add(ctrl StartDate)

If Page.IsPostBack Then
litDateFrom.Tex t = ctrlStartDate.c urrDate.ToStrin g
Else
ctrlStartDate.c urrDate = Now
End If

***datebox.ascx
<asp:panel id="pnlDateCont rol" runat="server"/>

***datebox.ascx .vb
Public Class DateBox
Inherits System.Web.UI.U serControl

Protected WithEvents pnlDateControl As System.Web.UI.W ebControls.Pane l
Private m_ControlName As String
Private m_CurrDate As Date

WriteOnly Property ControlName() As String
Set(ByVal Value As String)
m_ControlName = Value
End Set
End Property

Property currDate() As Date
Get
Return m_CurrDate
End Get
Set(ByVal Value As Date)
m_CurrDate = Value
End Set
End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'build the boxes
Dim txtDay As New TextBox
Dim txtMonth As New DropDownList
Dim txtYear As New TextBox
Dim liMonth As ListItem
Dim iLoop As Integer

txtDay.ID = m_ControlName & "_Day"
txtDay.CssClass = "inputBox25 "
txtDay.MaxLengt h = 2
txtDay.Text = m_CurrDate.Day

txtMonth.ID = m_ControlName & "_Month"
txtMonth.CssCla ss = "inputBox"
For iLoop = 1 To 12
liMonth = New ListItem
liMonth.Value = iLoop
liMonth.Text = Left(MonthName( iLoop), 3)
If m_CurrDate.Mont h = iLoop Then liMonth.Selecte d = True
txtMonth.Items. Add(liMonth)
Next

txtYear.ID = m_ControlName & "_Year"
txtYear.CssClas s = "inputBox50 "
txtYear.MaxLeng th = 4
txtYear.Text = m_CurrDate.Year
pnlDateControl. Controls.Add(tx tDay)
pnlDateControl. Controls.Add(tx tMonth)
pnlDateControl. Controls.Add(tx tYear)
End Sub
End Class
Nov 17 '05 #1
2 4277
Hi Dunc,

Check out the MSDN article:
http://msdn.microsoft.com/library/de...nlifecycle.asp

The "Load" event occurs after the "Load ViewState" and "Process Postback"
events. Since the control doesn't exist yet anything from the previous page
gets lost. If you want to add a dynamic control and have it work you should
add it and its event handlers and such during the "Initialize " event.

Todd Thompson
Nov 17 '05 #2
Hi Todd,

Thanks for your feedback. I'm getting further, but still no cigar. Do you
know where I might find some example code?

Dunc

"Todd Thompson" <tl********@wes t.com> wrote in message
news:ea******** ******@TK2MSFTN GP10.phx.gbl...
Hi Dunc,

Check out the MSDN article:
http://msdn.microsoft.com/library/de...nlifecycle.asp
The "Load" event occurs after the "Load ViewState" and "Process Postback"
events. Since the control doesn't exist yet anything from the previous page gets lost. If you want to add a dynamic control and have it work you should add it and its event handlers and such during the "Initialize " event.

Todd Thompson

Nov 17 '05 #3

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

Similar topics

3
1963
by: Jen | last post by:
Hi I have created some controls (HtmlInputText, HtmlGenericControl, TextBox) dynamically. But I have problem getting the values from these controls to save them. Is there a way to do that? Regards and Many thanks Jen
1
3017
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g....
1
2572
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g. wucCustomerInfo.ascx,
9
2342
by: james.e.coleman | last post by:
Hello, I have created a custom dropdownlist that is used multiple times within a single page. When trying to set the values of the controls with the page in which they are being used, they all are set to the value of the last control. I found this link: http://www.codecomments.com/archive315-2005-1-366113.html which I think explains the situation but I'm not sure how to implement the solution in my case since I am not using a .ascx...
4
5039
by: Larry Grady | last post by:
Anyone up for a challenge? I've been struggling with this for a few days and was hoping someone could help me. Pouring through all the messageboards I just can't find the solution. We have a GridView that needs to be dynamically designed, depending on what collection of fields our uses want to edit for their product data. We have 400+ fields of information per product so they're selecting a subset of those fields to edit.
2
7051
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply. Each dynamically created row will return 3 values fee1_choice, fee1_unit and fee1_money. Note The above informaton is...
0
1133
by: jburnage | last post by:
I need help in getting the values from a dynamically added user control when a user submits a form. The controls are added to a placeholder and this all works fine - but its looping through the controls that i'm having trouble with. Its the "case 1:" statement that i need help with cheers in advance for any help my code is as follows. // a Property that manages a counter stored in ViewState protected int NumberOfSchemeControls
9
7925
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview contains a placeholder and I add the control to it, the user control is a formview bound to an object datsource. This works great until I post back the page and the user control disappears. What am I doing wrong? Regards, Chris. Protected Sub...
4
2967
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a while and it seems it's not possible because the row that gets added with each click won't get recreated after a post back. After all the reading it seems that any dynamically created controls must be created in the Init event to be recreated after...
0
8676
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
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
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
9029
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...
1
8897
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5860
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
4370
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
3050
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
3
2006
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.