Skip to content

Commit 29042f2

Browse files
Merge pull request #537 from roel-de-vries/add-webforms-example
Added .NET WebForms example
2 parents a6fcf87 + a608ac5 commit 29042f2

21 files changed

+748
-4
lines changed

ExampleNet45ASPNetProject/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ Update the "SendGridApiKey" appSettings variable within the web.config file.
1313

1414
## Steps
1515

16-
1. Open SendGrid.ASPSamples.sln
17-
2. Build the solution and run the project
16+
1. Open SendGrid.ASPSamples.sln
17+
2. Switch to one of the example project (right click on a project -> "Set as StartUp project")
18+
2. Build and run the project
1819

1920
You may need to download the latest Nuget executable and run `nuget.exe restore`
2021

ExampleNet45ASPNetProject/SendGrid.ASPSamples.sln

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.26730.16
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendGrid.ASPSamples", "SendGrid.ASPSamples\SendGrid.ASPSamples.csproj", "{14FA0F22-DFB2-4CE2-867A-242E75F64E1B}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendGrid.ASPWebFormsSamples", "SendGrid.ASPWebFormsSamples\SendGrid.ASPWebFormsSamples.csproj", "{0A24E647-5885-477C-A766-7385BCC6982E}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,8 +17,15 @@ Global
1517
{14FA0F22-DFB2-4CE2-867A-242E75F64E1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{14FA0F22-DFB2-4CE2-867A-242E75F64E1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{14FA0F22-DFB2-4CE2-867A-242E75F64E1B}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{0A24E647-5885-477C-A766-7385BCC6982E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{0A24E647-5885-477C-A766-7385BCC6982E}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{0A24E647-5885-477C-A766-7385BCC6982E}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{0A24E647-5885-477C-A766-7385BCC6982E}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE
2127
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {36445F8F-3714-4B6A-89DB-17DC0C001CF5}
30+
EndGlobalSection
2231
EndGlobal
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings" />
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Wrap content on words otherwise the body response overflows in the Well*/
2+
.well {
3+
word-wrap: break-word;
4+
}
5+
6+
/* Move down content because we have a fixed navbar that is 50px tall */
7+
body {
8+
padding-top: 50px;
9+
padding-bottom: 20px;
10+
}
11+
12+
/* Wrapping element */
13+
/* Set some basic padding to keep content from hitting the edges */
14+
.body-content {
15+
padding-left: 15px;
16+
padding-right: 15px;
17+
margin-top: 50px;
18+
}
19+
20+
/* Responsive: Portrait tablets and up */
21+
@media screen and (min-width: 768px) {
22+
.body-content {
23+
padding: 0;
24+
}
25+
}
26+
27+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<%@ Page Title="Home Page" Async="true" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SendGrid.ASPWebFormsSamples.Default" %>
2+
3+
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
4+
<div class="row">
5+
<div class="col-md-4">
6+
<div class="form-horizontal">
7+
<div class="form-group">
8+
<label class="col-md-2 control-label">From: </label>
9+
<div class="col-md-10">
10+
<input id="fromInput" runat="server" type="text" class="form-control" />
11+
</div>
12+
</div>
13+
14+
<div class="form-group">
15+
<label class="col-md-2 control-label">To: </label>
16+
<div class="col-md-10">
17+
<input id="toInput" runat="server" type="text" class="form-control"/>
18+
</div>
19+
</div>
20+
21+
<div class="form-group">
22+
<label class="col-md-2 control-label">Cc: </label>
23+
<div class="col-md-10">
24+
<input id="ccInput" runat="server" type="text" class="form-control"/>
25+
</div>
26+
</div>
27+
28+
<div class="form-group">
29+
<label class="col-md-2 control-label">Bcc: </label>
30+
<div class="col-md-10">
31+
<input id="bccInput" runat="server" type="text" class="form-control"/>
32+
</div>
33+
</div>
34+
35+
<div class="form-group">
36+
<label class="col-md-2 control-label">Subject: </label>
37+
<div class="col-md-10">
38+
<input id="subjectInput" runat="server" type="text" class="form-control"/>
39+
</div>
40+
</div>
41+
42+
<div class="form-group">
43+
<label class="col-md-2 control-label">Body: </label>
44+
<div class="col-md-10">
45+
<textarea id="bodyInput" runat="server" cols="20" rows="10" class="form-control"></textarea>
46+
</div>
47+
</div>
48+
49+
<div class="form-group">
50+
<div class="col-sm-offset-2 col-sm-10">
51+
<asp:Button ID="sendButton" runat="server" Text="Send" OnClick="sendButton_Click" CssClass="btn btn-default pull-right"/>
52+
</div>
53+
</div>
54+
</div>
55+
</div>
56+
57+
<div id="responseInfo" runat="server" class="col-md-8">
58+
<div id="responseStatus" runat="server" class="alert alert-info" role="alert"></div>
59+
60+
<span>Response body: </span>
61+
<div runat="server" id="responseBody" class="well"></div>
62+
</div>
63+
</div>
64+
</asp:Content>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using System.Web.UI;
4+
using SendGrid.ASPWebFormsSamples.Models;
5+
using SendGrid.ASPWebFormsSamples.Services;
6+
7+
namespace SendGrid.ASPWebFormsSamples
8+
{
9+
public partial class Default : Page
10+
{
11+
private readonly SendGridService _sendGridService;
12+
13+
protected Default()
14+
{
15+
_sendGridService = new SendGridService();
16+
}
17+
18+
protected void Page_Load(object sender, EventArgs e)
19+
{
20+
responseInfo.Visible = false;
21+
}
22+
23+
protected async void sendButton_Click(object sender, EventArgs e)
24+
{
25+
// Prepare the email message info model
26+
var messageInfo = new EmailMessageInfo
27+
{
28+
FromEmailAddress = fromInput.Value,
29+
ToEmailAddress = toInput.Value,
30+
CcEmailAddress = ccInput.Value,
31+
BccEmailAddress = bccInput.Value,
32+
EmailSubject = subjectInput.Value,
33+
EmailBody = bodyInput.Value
34+
};
35+
36+
// Make an API call, and save the response
37+
var apiResponse = await _sendGridService.Send(messageInfo);
38+
39+
await SetResponseInfoContainers(apiResponse);
40+
}
41+
42+
private async Task SetResponseInfoContainers(Response apiResponse)
43+
{
44+
responseInfo.Visible = true;
45+
responseStatus.InnerText = $"Statuscode {(int)apiResponse.StatusCode}: {apiResponse.StatusCode}";
46+
responseBody.InnerText = await apiResponse.Body.ReadAsStringAsync();
47+
}
48+
}
49+
}

ExampleNet45ASPNetProject/SendGrid.ASPWebFormsSamples/Default.aspx.designer.cs

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%@ Application Codebehind="Global.asax.cs" Inherits="SendGrid.ASPWebFormsSamples.Global" Language="C#" %>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Web;
3+
4+
namespace SendGrid.ASPWebFormsSamples
5+
{
6+
public class Global : HttpApplication
7+
{
8+
void Application_Start(object sender, EventArgs e)
9+
{
10+
// Code that runs on application startup
11+
}
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace SendGrid.ASPWebFormsSamples.Models
2+
{
3+
public class EmailMessageInfo
4+
{
5+
public string FromEmailAddress { get; set; }
6+
7+
public string ToEmailAddress { get; set; }
8+
9+
public string CcEmailAddress { get; set; }
10+
11+
public string BccEmailAddress { get; set; }
12+
13+
public string EmailSubject { get; set; }
14+
15+
public string EmailBody { get; set; }
16+
}
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("SendGrid.ASPWebFormsSamples")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("SendGrid.ASPWebFormsSamples")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("0a24e647-5885-477c-a766-7385bcc6982e")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Revision and Build Numbers
33+
// by using the '*' as shown below:
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)