Results 1 to 8 of 8

Thread: accessing field from user control

  1. #1

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    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:
    1. Public Class CalendarControl
    2.  
    3. Inherits System.Web.UI.UserControl
    4.  
    5. #Region " Web Form Designer Generated Code "
    6.  
    7. 'This call is required by the Web Form Designer.
    8.  
    9. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    10.  
    11. End Sub
    12.  
    13. Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar
    14.  
    15. Protected WithEvents txtClosed As System.Web.UI.WebControls.TextBox
    16.  
    17. Protected WithEvents txtIssueClosed As System.Web.UI.WebControls.TextBox
    18.  
    19. 'NOTE: The following placeholder declaration is required by the Web Form Designer.
    20.  
    21. 'Do not delete or move it.
    22.  
    23. Private designerPlaceholderDeclaration As System.Object
    24.  
    25. Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    26.  
    27. 'CODEGEN: This method call is required by the Web Form Designer
    28.  
    29. 'Do not modify it using the code editor.
    30.  
    31. InitializeComponent()
    32.  
    33. End Sub
    34.  
    35. #End Region
    36.  
    37. Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, _
    38.  
    39. ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
    40.  
    41. txtIssueClosed.Text = Format(Calendar1.SelectedDate, "dd-MMM-yy")
    42.  
    43. Dim div As System.Web.UI.Control = Page.FindControl("divCalendar")
    44.  
    45. If TypeOf div Is HtmlGenericControl Then
    46.  
    47. CType(div, HtmlGenericControl).Style.Add("display", "none")
    48.  
    49. End If
    50.  
    51. End Sub
    52.  
    53. Public Function GetClosedDate() As Date
    54.  
    55. GetClosedDate = txtIssueClosed.Text
    56.  
    57. End Function
    58.  
    59. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    60.  
    61. 'Put user code to initialize the page here
    62.  
    63. End Sub
    64.  
    65. 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

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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?

  4. #4

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    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

  5. #5

  6. #6

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    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

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    I'd slap someone with a soggy toad if I was you. They still using silly names?

    Isn't:
    VB Code:
    1. If txtIssueClosed.Text = "" Then
    a bit VB6'ish.

    Using .NET shouldn't you do:
    VB Code:
    1. 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

  8. #8

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    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
  •  



Click Here to Expand Forum to Full Width