?
Solved

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

Posted on 2009-12-22
8
Medium Priority
?
342 Views
Last Modified: 2012-06-21
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
Comment
Question by:westdh
  • 5
  • 3
8 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 26103383
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
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 2000 total points
ID: 26103399
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
 

Author Comment

by:westdh
ID: 26103644
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 36

Expert Comment

by:Miguel Oz
ID: 26103767
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
 

Author Comment

by:westdh
ID: 26103839
<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
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 26108377
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
 

Author Comment

by:westdh
ID: 26108923
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
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 26109769
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

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Viewers will learn the different options available in the Backstage view in Excel 2013.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question