|
-
Oct 9th, 2004, 10:45 AM
#1
Thread Starter
Banned
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
-
Oct 11th, 2004, 03:23 AM
#2
I get an error on the 1st line of html:
Code:
Inherits="ims.jakah.com.CalendarControl"
If I remove it then it sort of works, but clicking on a date doesn't populate my text box.
Are you sure you posted all the code?
Wooff
-
Oct 11th, 2004, 04:37 AM
#3
The last time I had a look at his project, the ims.jakah.com thing was causing problems too. It wasn't accepting it at all. You think the dots there are confusing vs.net?
And how is jhermiz getting it to work in the first place?
-
Oct 11th, 2004, 06:36 AM
#4
Thread Starter
Banned
Originally posted by mendhak
The last time I had a look at his project, the ims.jakah.com thing was causing problems too. It wasn't accepting it at all. You think the dots there are confusing vs.net?
And how is jhermiz getting it to work in the first place?
I got this to work now...minor problems sorry.
Thats the project name...
It had to be that because its on a remote server
-
Oct 11th, 2004, 07:09 AM
#5
Hang on, I showed you how to get the prop from a web usercontrol the other day....???? 

What was the problem?
Woof
-
Oct 11th, 2004, 07:12 AM
#6
Thread Starter
Banned
Originally posted by Wokawidget
Hang on, I showed you how to get the prop from a web usercontrol the other day....???? 

What was the problem?
Woof
I was being a very bad boy...
Problem with those stupid ID's the other programmers are giving them...
Decided to use Get / Set:
Code:
Public Property text() As String
Get
If txtIssueClosed.Text = "" Then
Return Nothing
Else
Return txtIssueClosed.Text
End If
End Get
Set(ByVal Value As String)
txtIssueClosed.Text = Value
End Set
End Property
-
Oct 11th, 2004, 08:00 AM
#7
I'd slap someone with a soggy toad if I was you. They still using silly names?
Isn't:
VB Code:
If txtIssueClosed.Text = "" Then
a bit VB6'ish.
Using .NET shouldn't you do:
VB Code:
If txtIssueClosed.Text.Length = 0 Then
Alernatively you could create a class and inherit from a textbox and create your own function called IsEmpty.
Woka
-
Oct 11th, 2004, 08:03 AM
#8
Thread Starter
Banned
Hmm nah dont need a class its just something simple...
And the length thing is ok..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|