Ask a Question related to ASP.NET General, Design and Development.
-
Duncan Welch #1
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.ControlName = "StartDate"
' Add the dynamic controls to their appropriate panels on the page
pnlStartDate.Controls.Add(ctrlStartDate)
If Page.IsPostBack Then
litDateFrom.Text = ctrlStartDate.currDate.ToString
Else
ctrlStartDate.currDate = Now
End If
***datebox.ascx
<asp:panel id="pnlDateControl" runat="server"/>
***datebox.ascx.vb
Public Class DateBox
Inherits System.Web.UI.UserControl
Protected WithEvents pnlDateControl As System.Web.UI.WebControls.Panel
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.EventArgs) 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.MaxLength = 2
txtDay.Text = m_CurrDate.Day
txtMonth.ID = m_ControlName & "_Month"
txtMonth.CssClass = "inputBox"
For iLoop = 1 To 12
liMonth = New ListItem
liMonth.Value = iLoop
liMonth.Text = Left(MonthName(iLoop), 3)
If m_CurrDate.Month = iLoop Then liMonth.Selected = True
txtMonth.Items.Add(liMonth)
Next
txtYear.ID = m_ControlName & "_Year"
txtYear.CssClass = "inputBox50"
txtYear.MaxLength = 4
txtYear.Text = m_CurrDate.Year
pnlDateControl.Controls.Add(txtDay)
pnlDateControl.Controls.Add(txtMonth)
pnlDateControl.Controls.Add(txtYear)
End Sub
End Class
Duncan Welch Guest
-
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created)
Ok here's my scenario. I have a Custom Composite Server Control (CCSC) consisting of a TextBox, Button & Panel. (And some other code - which I... -
saving text values of dynamically created textboxes
I have many textboxes that are created dynamically as child controls of my custom control. I know that I must recreate them after each postback... -
Retrieving Values from dynamically created controls in a user control
Hi, Dynamic control should be load every time page load, even on post back. take out control creation from IsPostBack condition. Natty Gur ... -
retrieving values from dynamically created controls
Hi, Someone please clear this for me! I display a bunch of button controls on a page dynamically, adding them to a placeholder control in my... -
need help with dynamically created user control
i have a dynamically created user control which contains a non-dynamically created ASP.Net button. When the button is clicked, the event is not... -
Todd Thompson #2
Re: returning values from dynamically created user control
Hi Dunc,
Check out the MSDN article:
[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrolexecutionlifecycle.asp[/url]
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
Todd Thompson Guest
-
Duncan Welch #3
Re: returning values from dynamically created user control
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" <tlthompson@west.com> wrote in message
news:eaAItHKQDHA.2432@TK2MSFTNGP10.phx.gbl...[url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrolexecutionlifecycle.asp[/url]> Hi Dunc,
>
> Check out the MSDN article:
>page>
> The "Load" event occurs after the "Load ViewState" and "Process Postback"
> events. Since the control doesn't exist yet anything from the previousshould> gets lost. If you want to add a dynamic control and have it work you> add it and its event handlers and such during the "Initialize" event.
>
> Todd Thompson
Duncan Welch Guest



Reply With Quote

