Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes anyone know of an ASP.Net E-mail control/user control?
    primarykey
    data
    text
    <p>I'm implementing a messaging system in my program. It functions just like e-mail except that it is entirely contained within the system.</p> <p>I was wondering if anyone has seen an e-mail control template that I could modify. It would have stuff like an inbox, message viewing and message sending parts.</p> <p>I would just rewire the mail sending &amp; receiving parts to my hook up to my tables.</p> <p>Thanks!</p> <p>Edit:</p> <p>Ok I didn't realize I wrote so much. Make sure you credit Biff_MaGriff if you use this. :D Tech is .net 3.5 with SubSonic 3.0</p> <p>The rest is in my answer.</p> <p>Should look like this in the end. (Minus all my cut outs)</p> <p><img src="https://i.stack.imgur.com/GLgbU.jpg" alt="alt text"></p> <p>web.config</p> <pre><code>&lt;pages&gt; &lt;controls&gt; ... &lt;add tagPrefix="cc" tagName="MessageFolder" src="~/UserControls/Messages/MessageFolder/MessageFolder.ascx"/&gt; &lt;add tagPrefix="cc" tagName="MessageView" src="~/UserControls/Messages/MessageView/MessageView.ascx"/&gt; &lt;add tagPrefix="cc" tagName="MessageCompose" src="~/UserControls/Messages/MessageCompose/MessageCompose.ascx"/&gt; &lt;add tagPrefix="cc" tagName="MessageBox" src="~/UserControls/Messages/MessageBox/MessageBox.ascx"/&gt; ... &lt;/controls&gt; &lt;pages&gt; </code></pre> <p>App_Code/IMessageFolder.cs</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; /// &lt;summary&gt; /// Summary description for IMessageFolder /// &lt;/summary&gt; public interface IMessageFolder { int? MessageID { get; } } </code></pre> <p>App_Code/CustomDataViews.cs</p> <pre><code>using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.Linq; using System.Linq; using System.Web; /// &lt;summary&gt; /// Summary description for CustomDataViews /// &lt;/summary&gt; public class CustomDataViews { //Subsonic db static VAC.Data.VACDB db = new VAC.Data.VACDB(); public class MessageQuery { public class Message { public int MessageID { get; set; } public string FromUser { get; set; } public string ToUser { get; set; } public DateTime SentDate { get; set; } public string Subject { get; set; } public string Body { get; set; } public bool IsDeletedSender { get; set; } public bool IsDeletedRecipient { get; set; } public bool IsRead { get; set; } } public enum MailType { ReceivedMail, SentMail }; public Message[] GetMessages(MailType mt, bool showDeleted) { List&lt;Message&gt; myMessages = new List&lt;Message&gt;(); foreach (var v in (from m in db.Messages where (mt == MailType.ReceivedMail ? m.ToUserID : m.FromUserID) == Common.CurrentUserID &amp;&amp; (showDeleted || !(mt == MailType.ReceivedMail ? m.IsDeletedRecipient : m.IsDeletedSender)) orderby m.SentDate descending select m)) { Message mess = new Message(); mess.MessageID = v.MessageID; mess.FromUser = (from u in db.Users where u.UserID == v.FromUserID select u.UserName).First(); mess.ToUser = (from u in db.Users where u.UserID == v.ToUserID select u.UserName).First(); mess.SentDate = v.SentDate; mess.Subject = v.Subject; mess.Body = v.Body; mess.IsDeletedSender = v.IsDeletedSender; mess.IsDeletedRecipient = v.IsDeletedRecipient; mess.IsRead = v.IsRead; myMessages.Add(mess); } return myMessages.ToArray(); } public Message GetMessage(int MessageID) { var myMessage = (from m in db.Messages where m.MessageID == MessageID select m); if (myMessage.Count() == 1) { var v = myMessage.First(); Message mess = new Message(); mess.MessageID = v.MessageID; mess.FromUser = (from u in db.Users where u.UserID == v.FromUserID select u.UserName).First(); mess.ToUser = (from u in db.Users where u.UserID == v.ToUserID select u.UserName).First(); mess.SentDate = v.SentDate; mess.Subject = v.Subject; mess.Body = v.Body; return mess; } else return null; } } } </code></pre> <p>App_Code/Common.cs</p> <pre><code>using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.SessionState; using System.Web.Configuration; using System.Data; using System.Text; using System.Collections; using System.Globalization; using System.Linq; /// &lt;summary&gt; /// Summary description for Common /// &lt;/summary&gt; public class Common { /// &lt;summary&gt; /// Retrieves the index of the column from the gridview. Returns -1 if not found. /// &lt;/summary&gt; /// &lt;param name="gv"&gt;&lt;/param&gt; /// &lt;param name="columnName"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; static public int GetColumnIndex(GridView gv, string columnName) { int returnMe = -1; for (int i = 0; i &lt; gv.Columns.Count; i++) { if (gv.Columns[i].HeaderText == columnName) { returnMe = i; break; } } return returnMe; } //Colours for gridviews static public string BGColourRed = "#FF8888"; static public string BGColourRedAlternate = "#FF0000"; static public string BGColourBlue = "#AAAAFF"; static public string BGColourBlueAlternate = "#4444FF"; static public string BGColourGreen = "#2bf053"; static public string BGColourGreenAlternate = "#27c319"; static public string BGColourOrange = "#FFA365"; static public string BGColourOrangeAlternate = "#FF6600"; static public string NormalBGColour(object sender) { return "#" + ((GridView)sender).RowStyle.BackColor.R.ToString("X") + ((GridView)sender).RowStyle.BackColor.G.ToString("X") + ((GridView)sender).RowStyle.BackColor.B.ToString("X"); } static public string AlternateBGColour(object sender) { return "#" + ((GridView)sender).AlternatingRowStyle.BackColor.R.ToString("X") + ((GridView)sender).AlternatingRowStyle.BackColor.G.ToString("X") + ((GridView)sender).AlternatingRowStyle.BackColor.B.ToString("X"); } static public string SelectedBGColour(object sender) { string selectedBGColour = "#165EA9"; if (!((GridView)sender).SelectedRowStyle.BackColor.IsEmpty) { selectedBGColour = "#" + ((GridView)sender).SelectedRowStyle.BackColor.R.ToString("X") + ((GridView)sender).SelectedRowStyle.BackColor.G.ToString("X") + ((GridView)sender).SelectedRowStyle.BackColor.B.ToString("X"); } return selectedBGColour; } /// &lt;summary&gt; /// Gridview RowDataBound extension. /// Allows row selection by clicking on a row and highlights the row in yellow on the mouse hover. /// &lt;/summary&gt; /// &lt;param name="sender"&gt;&lt;/param&gt; /// &lt;param name="e"&gt;&lt;/param&gt; static public void GridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.DataItemIndex == -1) return; //e.Row.Attributes.Add("onclick", ((GridView)sender).Page.ClientScript.GetPostBackEventReference((GridView)sender, "Select$" + e.Row.RowIndex.ToString(), false)); string selectedBGColour = SelectedBGColour(sender); string normalBGColour = NormalBGColour(sender); string alternateBGColour = AlternateBGColour(sender); ApplyStylingToRow(e.Row, selectedBGColour, normalBGColour, alternateBGColour); } static public void ApplyStylingToRow(GridViewRow row, string selectedBGColour, string normalBGColour, string alternateBGColour) { AppendAttribute(row, "onMouseOver", "this.style.cursor='pointer'; this.style.background='yellow';"); AppendAttribute(row, "onMouseOut", "this.style.background='" + ((row.RowState &amp; DataControlRowState.Selected) == DataControlRowState.Selected ? selectedBGColour : (row.RowState &amp; DataControlRowState.Alternate) == DataControlRowState.Alternate ? alternateBGColour : normalBGColour) + "';"); } static public void GridViewAddRowClick(GridView gv, GridViewRow row, bool isRender) { AppendAttribute(row, "onclick", gv.Page.ClientScript.GetPostBackEventReference(gv, "Select$" + row.RowIndex.ToString(), isRender) + ";"); /* for (int i = 0; i &lt; gv.Columns.Count; i++) if (!string.IsNullOrEmpty(gv.Columns[i].HeaderText) &amp;&amp; row.Cells.Count &gt; 1) AppendAttribute(row.Cells[i], "onclick", gv.Page.ClientScript.GetPostBackEventReference(gv, "Select$" + row.RowIndex.ToString(), isRender) + ";"); * */ } static public void GridViewRowClick_Render(GridView gv) { foreach (GridViewRow row in gv.Rows) if (row.RowType == DataControlRowType.DataRow) GridViewAddRowClick(gv, row, true); gv.Page.ClientScript.RegisterForEventValidation(gv.UniqueID); } /// &lt;summary&gt; /// Hides a column on a gridview. /// &lt;/summary&gt; /// &lt;param name="gv"&gt;&lt;/param&gt; /// &lt;param name="columnIndex"&gt;&lt;/param&gt; static public void HideColumn(GridView gv, int columnIndex) { if (gv.HeaderRow != null) gv.HeaderRow.Cells[columnIndex].Style.Add("display", "none"); foreach (GridViewRow row in gv.Rows) { if (row.RowType == DataControlRowType.DataRow) row.Cells[columnIndex].Style.Add("display", "none"); } } /// &lt;summary&gt; /// Registers javascript to be run. /// &lt;/summary&gt; /// &lt;param name="con"&gt;&lt;/param&gt; /// &lt;param name="script"&gt;&lt;/param&gt; static public void RegisterStartupScript(object con, string script) { RegisterStartupScript((Control)con, script); } /// &lt;summary&gt; /// Capitalizes the beginning of strings /// &lt;/summary&gt; /// &lt;param name="strText"&gt;&lt;/param&gt; public static string InitCap(string strText) { return new CultureInfo("en").TextInfo.ToTitleCase(strText.ToLower()); } /// &lt;summary&gt; /// Registers javascript to be run. /// &lt;/summary&gt; /// &lt;param name="con"&gt;&lt;/param&gt; /// &lt;param name="script"&gt;&lt;/param&gt; static public void RegisterStartupScript(Control con, string script) { ScriptManager sm = ScriptManager.GetCurrent(con.Page); if (sm != null) ScriptManager.RegisterStartupScript(con, con.GetType(), Guid.NewGuid().ToString(), script, true); else con.Page.ClientScript.RegisterStartupScript(typeof(Page), Guid.NewGuid().ToString(), script, true); } /// &lt;summary&gt; /// Registers a javascript file to be included in the page. /// &lt;/summary&gt; /// &lt;param name="con"&gt;&lt;/param&gt; /// &lt;param name="url"&gt;&lt;/param&gt; static public void RegisterClientScriptInclude(Control con, string url) { ScriptManager sm = ScriptManager.GetCurrent(con.Page); if (sm != null) ScriptManager.RegisterClientScriptInclude(con, con.GetType(), Guid.NewGuid().ToString(), System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath + url); else con.Page.ClientScript.RegisterClientScriptInclude(typeof(Page), Guid.NewGuid().ToString(), System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath + url); } public static int CurrentUserID { get { return (from u in new VAC.Data.VACDB().Users where u.UserName == HttpContext.Current.User.Identity.Name select u.UserID).First(); } } public class MessageComposeEventArgs : EventArgs { public int? SendToUserID { get; set; } public string Subject { get; set; } public MessageComposeEventArgs() { } public MessageComposeEventArgs(int SendToUserID) { this.SendToUserID = SendToUserID; } public MessageComposeEventArgs(int SendToUserID, string Subject) { this.SendToUserID = SendToUserID; this.Subject = Subject; } } } </code></pre> <p>App_Code/ExtendedCommandField.cs</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; /// &lt;summary&gt; /// An extended &lt;see cref="CommandField"/&gt; that allows deletions /// to be confirmed by the user. /// &lt;/summary&gt; public class ExtendedCommandField : CommandField { /// &lt;summary&gt; /// Initialize the cell. /// &lt;/summary&gt; public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) { base.InitializeCell(cell, cellType, rowState, rowIndex); if (!string.IsNullOrEmpty(this.DeleteConfirmationText) &amp;&amp; this.ShowDeleteButton) { foreach (Control control in cell.Controls) { IButtonControl button = control as IButtonControl; if (button != null &amp;&amp; button.CommandName == "Delete") // Add delete confirmation ((WebControl)control).Attributes.Add("onclick", string.Format ("if (!confirm('{0}')) return false;", this.DeleteConfirmationText)); } } } #region DeleteConfirmationText /// &lt;summary&gt; /// Delete confirmation text. /// &lt;/summary&gt; [Category("Behavior")] [Description("The text shown to the user to confirm the deletion.")] public string DeleteConfirmationText { get { return this.ViewState["DeleteConfirmationText"] as string; } set { this.ViewState["DeleteConfirmationText"] = value; } } #endregion } </code></pre> <p>~/UserControls/Messages/MessageFolder/MessageFolder.ascx</p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="MessageFolder.ascx.cs" Inherits="UserControls_Messages_MessageFolder_MessageFolder" %&gt; &lt;asp:UpdatePanel ID="up1" runat="server"&gt; &lt;ContentTemplate&gt; &lt;asp:HiddenField ID="hfMessageID" runat="server" /&gt; &lt;asp:Button ID="butRefresh" runat="server" Text="Check for new Messages" /&gt;&lt;asp:Button ID="butCompose" runat="server" Text="Compose New Message" OnClick="butCompose_Click" /&gt;&lt;asp:CheckBox AutoPostBack="true" ID="cbShowDeleted" runat="server" Text="Show Deleted Messages" OnCheckedChanged="cbShowDeleted_CheckChanged" /&gt; &lt;asp:GridView ID="gvMessages" runat="server" DataKeyNames="MessageID" AutoGenerateColumns="false" OnRowDataBound="gvMessages_RowDataBound" OnSelectedIndexChanged="gvMessages_SelectedIndexChanged" OnRowDeleting="gvMessages_RowDeleting" Width="100%" Style="float: left;"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="MessageID" InsertVisible="false" /&gt; &lt;cc:ExtendedCommandField DeleteConfirmationText="Are you certain you wish to delete this record?" DeleteText="Delete" ShowDeleteButton="true" /&gt; &lt;asp:BoundField DataField="FromUser" HeaderText="From" /&gt; &lt;asp:BoundField DataField="ToUser" HeaderText="To" /&gt; &lt;asp:TemplateField&gt; &lt;HeaderTemplate&gt; Sent Date&lt;/HeaderTemplate&gt; &lt;ItemTemplate&gt; &lt;asp:Label ID="lbl1" runat="server" Text='&lt;%# Bind("SentDate") %&gt;' Style="white-space: nowrap;" /&gt;&lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:BoundField DataField="Subject" HeaderText="Subject" ItemStyle-Width="100%" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload