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

I need to know how to access a ascx control (table data) in order to format the data, for the body text of an email message.

Need to know How to obtain the data from a control (ascx) and build a formatted txtfile.text for an email body text

register.aspx page --> the control tag refence
===============================
 <events:EventDetails id="ctlEvent" runat="server" ShowDetails="false" ShowDiscount="true" />

need to know how to access the control data to build a formatted string
------------------------------------------------------


EventDetails.ascx file
====================================================
<%@ Control Language="vb" Codebehind="EventDetails.ascx.vb" Inherits="i2Integration.Modules.EventReg.CustomControls.EventDetails" AutoEventWireup="false" Explicit="true" %>
<font class="SubHead">Event Information:</font>
<table id="tblForm" runat="server" cellpadding="3" summary="Event details layout table.">
      <tr id="rowID" runat="server" visible="false" EnableViewState="False">
            <td class="SubHead" vAlign="top">ID:</td>
            <td><asp:Label ID="lblEventID" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr id="rowStatus" runat="server" EnableViewState="False">
            <td class="SubHead" vAlign="top">Status:</td>
            <td><asp:Label ID="lblStatus" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr>
            <td class="SubHead" vAlign="top">Title:</td>
            <td><asp:Label ID="lblTitle" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr>
            <td class="SubHead" vAlign="top">Date:</td>
            <td><asp:Label ID="lblDate" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr>
            <td class="SubHead" vAlign="top">Summary:</td>
            <td><asp:Label ID="lblSummary" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr id="rowDetails" runat="server" EnableViewState="False">
            <td class="SubHead" vAlign="top">Details:</td>
            <td><asp:Label ID="lblDetails" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr id="rowViewStart" runat="server" EnableViewState="False">
            <td class="SubHead" vAlign="top">View Start:</td>
            <td><asp:Label ID="lblViewStart" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr id="rowViewEnd" runat="server" EnableViewState="False">
            <td class="SubHead" vAlign="top">View End:</td>
            <td><asp:Label ID="lblViewEnd" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr id="rowRegStart" runat="server" EnableViewState="False">
            <td class="SubHead" vAlign="top">Registration Begins:</td>
            <td><asp:Label ID="lblRegStart" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr id="rowRegEnd" runat="server" EnableViewState="False">
            <td class="SubHead" vAlign="top">Registration Ends:</td>
            <td><asp:Label ID="lblRegEnd" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>
      <tr id="rowDiscount" runat="server" EnableViewState="False">
            <td class="SubHead" vAlign="top">Discount:</td>
            <td><asp:Label ID="lblDiscount" Runat="server" CssClass="Normal" EnableViewState="False" /></td>
      </tr>      
      <tr id="rowExport" runat="server" enableviewstate="false">
      <td class="SubHead" valign="top">Export to Outlook:</td>
      <td><asp:LinkButton ID="lnkExportToOutlook" runat="server" Text="Add to calendar"></asp:LinkButton></td>
      </tr>
</table>
0
westdh
Asked:
westdh
  • 2
1 Solution
 
jorge_torizCommented:
In the code behind of your control, declare a public property that returns the text of the control you want to get, then in your page (aspx) get that property.
0
 
westdhAuthor Commented:
I am trying to access it from my aspx codebehind page:
this does not work 'MyUserControl" is in error

 Dim u As MyUserControl = TryCast(FindControl("EventDetails"), MyUserControl)
           
           Dim b As TextBox = TryCast(u.FindControl("lblTitle"), TextBox)
           If b IsNot Nothing Then
               Response.Write("Found lblTitle + b + ")
           End If
0
 
jorge_torizCommented:
You must add a "Reference" directive in your page pointing to your control through virtual path attribute
0
 
shrinivasmwCommented:
See problem is - you are accessing usercontrol with wrong identifier.
Your control's id is in page: ctlEvent

so try this

Dim u As MyUserControl = TryCast(FindControl("ctlEvent"), MyUserControl)
Once you got the control, you can access further controls inside that using findcontrol again.

Let me know if it works or you need more info.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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