Link to home
Start Free TrialLog in
Avatar of westdh
westdhFlag for United States of America

asked on

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>
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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;
}
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of westdh

ASKER

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
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.
Avatar of westdh

ASKER

<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]" />
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)
Avatar of westdh

ASKER

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>
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")