-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDefault.aspx.cs
More file actions
81 lines (71 loc) · 2.42 KB
/
Default.aspx.cs
File metadata and controls
81 lines (71 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using Websms;
namespace ASPExample
{
public partial class Default : System.Web.UI.Page
{
private static string URL = "https://api.websms.com/json";
private static uint MAX_SMS_PER_MESSAGE = 1;
private static bool TEST_MESSAGE = true;
// webmsms.com username
private static string USERNAME = "";
// websms.com password
private static string PASSWORD = "";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Validate_Recipient(object source, ServerValidateEventArgs args)
{
Regex regx = new Regex("^\\d{1,20}$");
if (Recipient.Text.Length == 0)
{
RecipientValidator.ErrorMessage = "Required";
args.IsValid = false;
}
else if (regx.IsMatch(Recipient.Text) == false)
{
RecipientValidator.ErrorMessage = "Not a valid number";
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
protected void Send_Click(object sender, EventArgs e)
{
Page.Validate();
if (!Page.IsValid)
{
Output.Style.Add("color", "black");
Output.Text = "-";
return;
}
// Create the client.
SmsClient client = new SmsClient(USERNAME, PASSWORD, URL);
// Create new message with one recipient.
TextMessage textMessage = new TextMessage(Int64.Parse(Recipient.Text), Text.Text);
try
{
// Send the message.
MessageResponse response = client.Send(textMessage, MAX_SMS_PER_MESSAGE, TEST_MESSAGE);
// Print the response.
Output.Style.Add("color", "black");
Output.Text = response.statusMessage;
Text.Text = "";
}
catch (Exception ex)
{
// Handle exceptions.
Output.Style.Add("color", "red");
Output.Text = ex.Message;
}
}
}
}