sending messages to mobile by using way2sms credentials.
Code in message.aspx source
<body>
<form id="form1" runat="server">
<div>
<center>
<asp:Panel ID="pnldetails" runat="server" BackColor="#FFCCFF" Height="300px"
Width="520px">
<table class="style1">
<tr>
<td colspan="2">
<asp:Label ID="lblstatement" runat="server" Font-Size="Large" Font-Bold="true" Text="Message Sending...."
ForeColor="Blue"></asp:Label>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lbluserid" runat="server" Font-Bold="true" Text="UserId:"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtuserid" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lblpassword" runat="server" Text="PassWord:" Font-Bold="true"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lblmobileno" runat="server" Text="MobileNumber:" Font-Bold="true"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtmobileno" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lblmessage" runat="server" Text="Message:" Font-Bold="true"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtmessage" runat="server" TextMode="MultiLine" onkeyup="Javascript:CharactersCount();"
Style="overflow: hidden;" Height="80px" Width="300px" MaxLength="160"></asp:TextBox>
<div style="float: right;">
<span style="font-family: Verdana; font-size: 12px; color:Blue;">Left:</span>
<asp:Label ID="lblChar" runat="server" Text="160" ForeColor="Red"></asp:Label>
</div>
</td>
</tr>
<tr>
<td class="style2">
<asp:Button ID="btnsend" runat="server" ForeColor="Blue" Font-Bold="true" Text="Send"
OnClick="btnsend_Click" OnClientClick="return validate()" />
</td>
<td class="style3">
</td>
</tr>
</table>
</asp:Panel>
</center>
</div>
</form>
</body>
code in message.aspx.cs file
before writing code in message.cs file we should write the namespaces
using System.Net;
using System.IO;
protected void btnsend_Click(object sender, EventArgs e)
{
if (txtuserid.Text != null & txtpassword.Text != null & txtmobileno.Text != null & txtmessage.Text != null)
{
sending(txtuserid.Text, txtpassword.Text, txtmobileno.Text, txtmessage.Text);
Response.Write("'<script>alert('Message sent Successfully.....')</script>'");
}
}
public void sending(string Uid, string Password, string Number, string Message)
{
btnsend.Attributes.Add("onclick", "return validate()");
// Create a request using a URL that can receive a post.
HttpWebRequest myReq =(HttpWebRequest)WebRequest.Create("http://ubaid.tk/sms/sms.aspx?uid=" + Uid + "&pwd=" + Password +
"&phone=" + Number + "&msg=" + Message + "&provider=way2sms");
// Get the response.
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
// Close the Stream object.
respStreamReader.Close();
myResp.Close();
txtuserid.Text = string.Empty;
txtpassword.Text = string.Empty;
txtmobileno.Text = string.Empty;
txtmessage.Text = string.Empty;
}
i have written validations for controls in javascript, write this code in message.aspx source file,with in the head tag.
<script language="javascript" type="text/javascript">
function validate() {
if (document.getElementById("<%=txtuserid.ClientID%>").value == "") {
alert("Should be entered UserId");
document.getElementById("<%=txtuserid.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtpassword.ClientID%>").value == "") {
alert("Enter your Password");
document.getElementById("<%=txtpassword.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtmobileno.ClientID%>").value == "") {
alert("Enter Mobile number");
document.getElementById("<%=txtmobileno.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtmessage.ClientID%>").value == "") {
alert("Enter Message Body");
document.getElementById("<%=txtmessage.ClientID%>").focus();
return false;
}
return true;
}
function CharactersCount() {
var CharLength = '<%=txtmessage.MaxLength %>';
var txtMsg = document.getElementById('txtmessage');
var lblCount = document.getElementById('lblChar');
if (txtMsg.value.length > CharLength) {
txtMsg.value = txtMsg.value.substring(0, CharLength);
}
lblCount.innerHTML = CharLength - txtMsg.value.length;
}
</script>
Code in message.aspx source
<body>
<form id="form1" runat="server">
<div>
<center>
<asp:Panel ID="pnldetails" runat="server" BackColor="#FFCCFF" Height="300px"
Width="520px">
<table class="style1">
<tr>
<td colspan="2">
<asp:Label ID="lblstatement" runat="server" Font-Size="Large" Font-Bold="true" Text="Message Sending...."
ForeColor="Blue"></asp:Label>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lbluserid" runat="server" Font-Bold="true" Text="UserId:"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtuserid" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lblpassword" runat="server" Text="PassWord:" Font-Bold="true"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtpassword" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lblmobileno" runat="server" Text="MobileNumber:" Font-Bold="true"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtmobileno" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="lblmessage" runat="server" Text="Message:" Font-Bold="true"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtmessage" runat="server" TextMode="MultiLine" onkeyup="Javascript:CharactersCount();"
Style="overflow: hidden;" Height="80px" Width="300px" MaxLength="160"></asp:TextBox>
<div style="float: right;">
<span style="font-family: Verdana; font-size: 12px; color:Blue;">Left:</span>
<asp:Label ID="lblChar" runat="server" Text="160" ForeColor="Red"></asp:Label>
</div>
</td>
</tr>
<tr>
<td class="style2">
<asp:Button ID="btnsend" runat="server" ForeColor="Blue" Font-Bold="true" Text="Send"
OnClick="btnsend_Click" OnClientClick="return validate()" />
</td>
<td class="style3">
</td>
</tr>
</table>
</asp:Panel>
</center>
</div>
</form>
</body>
code in message.aspx.cs file
before writing code in message.cs file we should write the namespaces
using System.Net;
using System.IO;
protected void btnsend_Click(object sender, EventArgs e)
{
if (txtuserid.Text != null & txtpassword.Text != null & txtmobileno.Text != null & txtmessage.Text != null)
{
sending(txtuserid.Text, txtpassword.Text, txtmobileno.Text, txtmessage.Text);
Response.Write("'<script>alert('Message sent Successfully.....')</script>'");
}
}
public void sending(string Uid, string Password, string Number, string Message)
{
btnsend.Attributes.Add("onclick", "return validate()");
// Create a request using a URL that can receive a post.
HttpWebRequest myReq =(HttpWebRequest)WebRequest.Create("http://ubaid.tk/sms/sms.aspx?uid=" + Uid + "&pwd=" + Password +
"&phone=" + Number + "&msg=" + Message + "&provider=way2sms");
// Get the response.
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
string responseString = respStreamReader.ReadToEnd();
// Close the Stream object.
respStreamReader.Close();
myResp.Close();
txtuserid.Text = string.Empty;
txtpassword.Text = string.Empty;
txtmobileno.Text = string.Empty;
txtmessage.Text = string.Empty;
}
i have written validations for controls in javascript, write this code in message.aspx source file,with in the head tag.
<script language="javascript" type="text/javascript">
function validate() {
if (document.getElementById("<%=txtuserid.ClientID%>").value == "") {
alert("Should be entered UserId");
document.getElementById("<%=txtuserid.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtpassword.ClientID%>").value == "") {
alert("Enter your Password");
document.getElementById("<%=txtpassword.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtmobileno.ClientID%>").value == "") {
alert("Enter Mobile number");
document.getElementById("<%=txtmobileno.ClientID%>").focus();
return false;
}
if (document.getElementById("<%=txtmessage.ClientID%>").value == "") {
alert("Enter Message Body");
document.getElementById("<%=txtmessage.ClientID%>").focus();
return false;
}
return true;
}
function CharactersCount() {
var CharLength = '<%=txtmessage.MaxLength %>';
var txtMsg = document.getElementById('txtmessage');
var lblCount = document.getElementById('lblChar');
if (txtMsg.value.length > CharLength) {
txtMsg.value = txtMsg.value.substring(0, CharLength);
}
lblCount.innerHTML = CharLength - txtMsg.value.length;
}
</script>
No comments:
Post a Comment