• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

Need to know how to access a user control (.ascx) to build a StringBuilder() in another User Control

Here is some data on my compile error ->
so here is some more data on this line that is giving me an error located in register.ascx
 --> For Each dg As DataList In ctlAttendees.grdAttendees.Rows

Error#           'i2Integration.Modules.EventReg.CustomControls.AttendeeList.Protected WithEvents grdAttendees As System.Web.UI.WebControls.DataGrid' is not accessible in this context because it is 'Protected'.      C:\Documents and Settings\Dennis West\Local Settings\Temp\VWDWebCache\cmaanorcalevents.com\DesktopModules\i2Integration - Events\user\Register.ascx      

this is my -> Register.ascx User control
====================================================
<%@ Control Language="vb" Codebehind="Register.ascx.vb" Inherits="i2Integration.Modules.EventReg.Register"
    AutoEventWireup="false" Explicit="true" %>
<%@ Register TagPrefix="events" TagName="EventDetails" Src="../controls/EventDetails.ascx" %>
<%@ Register TagPrefix="events" TagName="AttendeeList" Src="../controls/AttendeeList.ascx" %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Security" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Web.UI.Control" %>
<%@ Import Namespace="System.Net.Mail" %>

   <script runat="server" language="vb">
       
     Protected Sub EmailRegAttendeeNotices_Click(ByVal sender As Object, ByVal e As EventArgs)

             Dim sb As New StringBuilder()
             Dim x As UserControl = TryCast(FindControl("AttendeeList"), UserControl)
 error->    For Each dr As DataRow In ctlAttendees.grdAttendees.Rows
                sb.Append(ctlAttendees.grdAttendees.DataKeys(dr.RowIndex)              ("strBadgeName").ToString())
                sb.Append(",")
            Next
           
           If sb.ToString() <> "" Then
               'Response.Write(sb.ToString())
               Dim msg As New MailMessage("dennis@xxxxxxxxxxxx.com", sb.ToString())
               msg.Subject = "test"  'txtEmailSubject.Value
               msg.Body = "test" 'txtArea.Value

               Dim sc As New SmtpClient("smtp.xxxxxx.com", 25)
               sc.Credentials = New Net.NetworkCredential("dxxxx@dianewestdesign.com", "xxxxxxxxxx")
               sc.EnableSsl = False
               Try
                   sc.Send(msg)
                   Response.Write("<B>Email Has been sent successfully.</B>")
               Catch ex As Exception
                   Response.Write(ex.Message)
               End Try
           End If

       End Sub
       
   </script>

<asp:Label ID="lblError" runat="server" CssClass="NormalRed" EnableViewState="false"
    Visible="false" />
<asp:Panel ID="pnlMain" runat="server">
    <events:EventDetails id="ctlEvent" runat="server" ShowDetails="false" ShowDiscount="true" />
    <br />
    &nbsp; * If you are registering and today&#39;s date is within 3 days of the event date,
    add a $10.00 late fee.<br />
    &nbsp;&nbsp;&nbsp;&nbsp; Please select the appropriate member or non-member late Fee.<br />
    <table border="0" cellspacing="0" cellpadding="2" summary="Layout design table."
        id="tblAddAttendee" runat="server">
        <tr class="SubHead">

            <td>Attendee Name<br />
                First & Last Name:</td>

            <td>
                Attendee Email:</td>

            <td>
                Attendee Type and Cost:</td>

            <td>
                &nbsp;</td>

        </tr>
        <tr>

            <td>
                <asp:TextBox ID="txtAddUserTypeName" runat="server" CssClass="NormalTextbox" EnableViewState="False" />
            </td>

            <td>
                <asp:TextBox ID="txtAddUserTypeBadgeName" runat="server" CssClass="NormalTextbox"
                    EnableViewState="False" />
            </td>

            <td>
                <asp:DropDownList ID="lstUserTypes" runat="server" CssClass="NormalTextbox" EnableViewState="False" />
            </td>

            <td>
                <asp:Button ID="cmdAddUserType" runat="server" Text="Add Attendee(s)" EnableViewState="False"
                    CssClass="CommandButton" ValidationGroup="EventRegAttendee" />
            </td>

        </tr>
           
    </table>
             
    <font class="SubHead">
    <br />
    Attendees:</font>
    <br />
    <events:AttendeeList ID="ctlAttendees" runat="server" />
    <br />
    <asp:Label ID="lblAttendeeLimitReached" runat="server" CssClass="SubHead"
        resourcekey="AttendeeLimitReached" Visible="false"></asp:Label>
    <asp:Label ID="lblAttendeesLeftMessage" runat="server" CssClass="SubHead"></asp:Label>
    <asp:Button ID="Button1" runat="server" CssClass="CommandButton"
        EnableViewState="False" Text="Email event notices to registered attendees"
        ValidationGroup="EventRegAttendee" Width="269px"  OnClick="EmailRegAttendeeNotices()" />
    <br />
             
    <br />
    <font class="SubHead">
        <label for='<%= txtNeeds.ClientID %>'>
            Special Needs:</label>
    </font>
    <br />
    <asp:TextBox ID="txtNeeds" runat="server" Height="100" Width="600" TextMode="MultiLine" />
    <br />
    <font class="SubHead">
        <label for='<%= txtNotes.ClientID %>'>
            Comments:</label>
    </font>
    <br />
    <asp:TextBox ID="txtNotes" runat="server" Height="100" Width="600" TextMode="MultiLine" />
    <br />
    <font class="SubHead">
        <label for='<%= radPayMethod.ClientID %>_0'>
            Payment Method:</label></font><asp:RadioButtonList ID="radPayMethod" runat="server" AutoPostBack="False" RepeatDirection="Horizontal"
        CssClass="Normal" />
    <asp:Label ID="lblPayLaterNote" runat="server" CssClass="Normal" EnableViewState="False" />
    <br />
    <asp:Label ID="lblDonation" runat="server" resourcekey="DonationLabel" CssClass="SubHead"></asp:Label>
    <asp:TextBox ID="txtDonation" runat="server"></asp:TextBox>
    <asp:Label ID="lblDonationMessage" runat="server" resourcekey="DonationMessageLabel"
        CssClass="SubHead"></asp:Label>
    <asp:RegularExpressionValidator ID="valDonation" runat="server" resourcekey="DonationValidator"
        ControlToValidate="txtDonation" ValidationExpression="^\d+(?:\.\d{0,2})?$"></asp:RegularExpressionValidator>
    <br />
    <br />
</asp:Panel>
<asp:HyperLink class="CommandButton CancelButton" ID="lnkCancel" runat="server" BorderStyle="none"
    Text="Cancel" EnableViewState="False" />
<asp:LinkButton class="CommandButton SubmitButton" ID="cmdSubmit" runat="server" BorderStyle="none"
    Text="Next" CausesValidation="False" EnableViewState="False" />
   


this is my attendee control:
===============================
<%@ Control Language="vb" Codebehind="AttendeeList.ascx.vb" Inherits="i2Integration.Modules.EventReg.CustomControls.AttendeeList"
    AutoEventWireup="false" Explicit="true" %>
<asp:Label ID="lblNoRecords" runat="server" resourcekey="NoAttendeesMessage" CssClass="Normal"
    EnableViewState="False" Visible="False" Text="No attendees found."></asp:Label><br />
   
<asp:DataGrid ID="grdAttendees" runat="server" summary="Attendees design table."
    CellPadding="4" CellSpacing="0" AllowPaging="False" AllowSorting="False" AutoGenerateColumns="False"
    ShowHeader="True" ShowFooter="True" HeaderStyle-CssClass="SubHead" ItemStyle-CssClass="Normal"
    FooterStyle-CssClass="SubHead" FooterStyle-HorizontalAlign="Right" >
    <Columns>
        <asp:BoundColumn DataField="intRegistrationUserID" HeaderText="IDColumn" FooterText=""
            Visible="false" ReadOnly="True" />
        <asp:BoundColumn DataField="strRegistrationUserName" HeaderText="NameColumn" FooterText="" />
        <asp:BoundColumn DataField="strBadgeName" HeaderText="NameOnBadgeColumn" FooterText="" />
        <asp:BoundColumn DataField="strUserTypeName" HeaderText="TypeColumn" FooterText="TOTAL:"
            ReadOnly="True" />
        <asp:BoundColumn DataField="fltRegistrationUserCost" HeaderText="CostColumn" ReadOnly="True"
            DataFormatString="{0:$#,##0.00}" ItemStyle-HorizontalAlign="Right" FooterText="" />
        <asp:ButtonColumn ButtonType="LinkButton" CommandName="remove" HeaderText="RemoveColumn"
            Text="[Remove]" />
    </Columns>
</asp:DataGrid>
0
westdh
Asked:
westdh
  • 5
  • 3
1 Solution
 
Miguel OzSoftware EngineerCommented:
grdAttendees is created as protected by default at attendee control

You either need to create a get method or a property to surface this value in code behind.

public DataGrid GetGrdAttendees()
{
   return grdAttendees;
}
0
 
Miguel OzSoftware EngineerCommented:
Forgot to add:
replace:
error->    For Each dr As DataRow In ctlAttendees.grdAttendees.Rows
with
For Each dr As DataRow In ctlAttendees.GetGrdAttendees()
.Rows

Note: The VB code for GetGrdAttendees is at follows: (in the attendee control code behind)
Function GetGrdAttendees() As Integer

        Return grdAttendees
End Function
0
 
westdhAuthor Commented:
I have put this into inline code in Attendees.ascx
Function GetGrdAttendees() As Integer ... then found that integer is not accepatable
        Return grdAttendees
End Function

So--- I change it to read..this seem to work
Function GetGrdAttendees() As DataGrid
        Return grdAttendees
End Function

But I do not see how this function is accessed
======================================
And I changed this: still Name 'grdAttendees' is not declared

        Dim sb As New StringBuilder()

        For Each dr As DataRow In ctlAttendees.GetGrdAttendees.Rows()
            sb.Append(ctlAttendees.grdAttendees.DataKeys(dr.RowIndex)("strBadgeName").ToString())
            sb.Append(",")
        Next
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Miguel OzSoftware EngineerCommented:
Can you tell me how ctlAttendees is defined?
I thought it contains a list of the user controls.. is it a list?
If so, ctlAttendees.GetGrdAttendees must change to ctlAttendees(idx).GetGrdAttendees
where idx is the index of the required attendee control.
0
 
westdhAuthor Commented:
<asp:DataGrid ID="grdAttendees" runat="server" summary="Attendees design table."
    CellPadding="4" CellSpacing="0" AllowPaging="False" AllowSorting="False" AutoGenerateColumns="False"
    ShowHeader="True" ShowFooter="True" HeaderStyle-CssClass="SubHead" ItemStyle-CssClass="Normal"
    FooterStyle-CssClass="SubHead" FooterStyle-HorizontalAlign="Right" >

 <Columns>
        <asp:BoundColumn DataField="intRegistrationUserID" HeaderText="IDColumn" FooterText=""
            Visible="false" ReadOnly="True" />
        <asp:BoundColumn DataField="strRegistrationUserName" HeaderText="NameColumn" FooterText="" />
        <asp:BoundColumn DataField="strBadgeName" HeaderText="NameOnBadgeColumn" FooterText="" />
        <asp:BoundColumn DataField="strUserTypeName" HeaderText="TypeColumn" FooterText="TOTAL:"
            ReadOnly="True" />
        <asp:BoundColumn DataField="fltRegistrationUserCost" HeaderText="CostColumn" ReadOnly="True"
            DataFormatString="{0:$#,##0.00}" ItemStyle-HorizontalAlign="Right" FooterText="" />
        <asp:ButtonColumn ButtonType="LinkButton" CommandName="remove" HeaderText="RemoveColumn"
            Text="[Remove]" />
0
 
Miguel OzSoftware EngineerCommented:
Sorry you posted grdAttendees, I need ctlAttendees  declaration and how this object is filled?
Note: It should be on your base page (i2Integration.Modules.EventReg.CustomControls.AttendeeList)
0
 
westdhAuthor Commented:
ok here it is...........

<%@ Control Language="vb" Codebehind="AttendeeList.ascx.vb" Inherits="i2Integration.Modules.EventReg.CustomControls.AttendeeList"
    AutoEventWireup="false" Explicit="true" %>
<asp:Label ID="lblNoRecords" runat="server" resourcekey="NoAttendeesMessage" CssClass="Normal"
    EnableViewState="False" Visible="False" Text="No attendees found."></asp:Label><br />
   
<asp:DataGrid ID="grdAttendees" runat="server" summary="Attendees design table."
    CellPadding="4" CellSpacing="0" AllowPaging="False" AllowSorting="False" AutoGenerateColumns="False"
    ShowHeader="True" ShowFooter="True" HeaderStyle-CssClass="SubHead" ItemStyle-CssClass="Normal"
    FooterStyle-CssClass="SubHead" FooterStyle-HorizontalAlign="Right" >
    <Columns>
        <asp:BoundColumn DataField="intRegistrationUserID" HeaderText="IDColumn" FooterText=""
            Visible="false" ReadOnly="True" />
        <asp:BoundColumn DataField="strRegistrationUserName" HeaderText="NameColumn" FooterText="" />
        <asp:BoundColumn DataField="strBadgeName" HeaderText="NameOnBadgeColumn" FooterText="" />
        <asp:BoundColumn DataField="strUserTypeName" HeaderText="TypeColumn" FooterText="TOTAL:"
            ReadOnly="True" />
        <asp:BoundColumn DataField="fltRegistrationUserCost" HeaderText="CostColumn" ReadOnly="True"
            DataFormatString="{0:$#,##0.00}" ItemStyle-HorizontalAlign="Right" FooterText="" />
        <asp:ButtonColumn ButtonType="LinkButton" CommandName="remove" HeaderText="RemoveColumn"
            Text="[Remove]" />
    </Columns>
</asp:DataGrid>
0
 
Miguel OzSoftware EngineerCommented:
Sorry your last post does not have it, I need ctlAttendees  declaration and how this object is filled?
Note: how is i2Integration.Modules.EventReg.CustomControls.AttendeeList declared?

AttendeeList.ascx.vb does not have what we need, look for the base class (
Inherits="i2Integration.Modules.EventReg.CustomControls.AttendeeList")
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now