accessing field from user control
got a question...
Lets say I have a user control for a calendar here is the html:
Code:
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="CalendarControl.ascx.vb" Inherits="ims.jakah.com.CalendarControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:textbox id="txtIssueClosed" Width="64px" runat="server"></asp:textbox>
<INPUT style="BACKGROUND-POSITION-X: center; BACKGROUND-IMAGE: url(../images/calendar.gif); WIDTH: 24px; BACKGROUND-REPEAT: no-repeat; FONT-FAMILY: Arial, SansSerif, Verdana; HEIGHT: 24px"
onclick="OnClick()" value="..." type="button">
<br>
<div id="divCalendar" style="DISPLAY: none; POSITION: absolute"><asp:calendar id="Calendar1" Width="200px" runat="server" CellPadding="4" BorderStyle="Outset"
BorderColor="#C7D6E4" Font-Names="Arial" Font-Size="8pt" Height="180px" ForeColor="Black" BackColor="White" BorderWidth="2px">
<TodayDayStyle ForeColor="Black" BackColor="#CCCCCC"></TodayDayStyle>
<SelectorStyle BackColor="#CCCCCC"></SelectorStyle>
<NextPrevStyle VerticalAlign="Bottom"></NextPrevStyle>
<DayHeaderStyle Font-Size="7pt" Font-Bold="True" BackColor="#CCCCCC"></DayHeaderStyle>
<SelectedDayStyle Font-Bold="True" ForeColor="White" BackColor="#666666"></SelectedDayStyle>
<TitleStyle Font-Bold="True" BorderColor="Black" BackColor="#999999"></TitleStyle>
<WeekendDayStyle BackColor="#FFFFCC"></WeekendDayStyle>
<OtherMonthDayStyle ForeColor="Gray"></OtherMonthDayStyle>
</asp:calendar></div>
<script>
function OnClick()
{
if( divCalendar.style.display == "none")
divCalendar.style.display = "";
else
divCalendar.style.display = "none";
}
</script>
The code behind is:
VB Code:
Public Class CalendarControl
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar
Protected WithEvents txtClosed As System.Web.UI.WebControls.TextBox
Protected WithEvents txtIssueClosed As System.Web.UI.WebControls.TextBox
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
txtIssueClosed.Text = Format(Calendar1.SelectedDate, "dd-MMM-yy")
Dim div As System.Web.UI.Control = Page.FindControl("divCalendar")
If TypeOf div Is HtmlGenericControl Then
CType(div, HtmlGenericControl).Style.Add("display", "none")
End If
End Sub
Public Function GetClosedDate() As Date
GetClosedDate = txtIssueClosed.Text
End Function
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
End Sub
End Class
I want to use this Calendar Control on another aspx page. So I dragged and dropped it in an ASPX file.
Now what I do is I can click the button the calendar appears I select a date and it sets that text box (txtIssueClosed). Now on this aspx I click save to save the record into a SQL db row (table). The problem is I cannot retreive txtIssueClosed no matter what I try. I had tried to declare Protected CalendarControl as CalendarControl under the inherits section of this "logissue.aspx" page but that doesnt work. I even created a function to grab the date back in the code behind of this CalendarControl.ascx file. You see it posted as GetClosedDate...but it always returns null. I tried everything but cannot get the date from this text box to be passed in my code...
If i try
CalendarControl.GetClosedDate this always returns nothing
Please help!
Thanks,
Jon