Asked by:
send sms

Question
-
User-374796569 posted
hello every one
my self patel saurin
i have developed mobile web application and one module will add like send the sms from aspx page. any one know how to send the sms to mobile cell phone using asp.net
please help me .
thank you
Regards,
saurin patelFriday, May 30, 2008 3:58 AM
All replies
-
User-595745061 posted
The first thing is that, you have to but some scope from any provider to send sms from .aspx page. Its a url type something and you have to pass parameters of mobile no, port, etc into that to send sms.
===================================
Well if you have that. Apply this code...
===================================
.aspx code -
<head runat="server">
<title>Untitled Page</title>
<script language="javascript">
function chkfrm()
{
if (document.frm_prop.txttitle.value=="" )
{
alert("Sender Name/Mobile should not be left blank.");
document.frm_prop.txttitle.focus();
return false;
}
if (document.frm_prop.txtmobileno.value=="" )
{
alert("Mobile No should not be left blank.");
document.frm_prop.txtmobileno.focus();
return false;
}
if (isInteger(document.frm_prop.txtmobileno.value) != true)
{
alert("Mobile Number should be integer only.");
document.frm_prop.txtmobileno.focus();
return false;
}
if (document.frm_prop.txtmessage.value=="" )
{
alert("Message Text should not be left blank.");
document.frm_prop.txtmessage.focus();
return false;
}
return true;
}
function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit) // if too long...trim it!
{
alert("Maximum length excide");
field.value = field.value.substring(0, maxlimit);
}
else
countfield.value = maxlimit - field.value.length;
}
function isInteger(s)
{
var i;
for (i = 0; i < s.length; i++)
{
// Check that current character is number.
var c = s.charAt(i) ;
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}
function DisplaySender(gateway)
{
if (gateway == "7")
trSender.style.display = "block";
else
trSender.style.display = "none";
}
function blockKeys()
{
if(event.shiftKey == true && (event.keyCode == 50 || event.keyCode == 54 || event.keyCode == 55 || event.keyCode == 222))
{
event.returnValue=false;
}
}
</script>
<LINK href="images/styles.css" type="text/css" rel="stylesheet">
</head>
<body>
<form id="form1" runat="server">
<div>
<TABLE id="tblfrm" borderColor="#ffffff" cellSpacing="0" cellPadding="4" width="100%" align="center"
bgColor="#ffffff" border="1" runat="server">
<TR bgColor="#bdd8e9">
<TD class="bottomline">Select Gateway<SPAN class="required">*</SPAN>:</TD>
<TD class="bottomline"><asp:dropdownlist id="ddlgateway" runat="server" CssClass="field" onchange = "DisplaySender(this.value);">
<asp:ListItem Value="7">India SMS</asp:ListItem>
</asp:dropdownlist></TD>
</TR>
<TR bgColor="#bdd8e9" id="trSender">
<TD class="bottomline">Sender Name/Mobile<SPAN class="required">* </SPAN>:</TD>
<TD class="bottomline"><asp:textbox id="txttitle" runat="server" CssClass="field"></asp:textbox></TD>
</TR>
<TR bgColor="#bdd8e9">
<TD class="bottomline">Mobile Number
<SPAN class="required">* </SPAN>:<BR>
(97150XXXXXXX)</TD>
<TD class="bottomline">
<asp:textbox id="txtmobileno" runat="server" CssClass="field"></asp:textbox></TD>
</TR>
<TR bgColor="#bdd8e9">
<TD class="bottomline">Message Text
<SPAN class="required">*</SPAN><SPAN class="required"></SPAN>
:</TD>
<TD class="bottomline">
<asp:textbox id="txtmessage" onkeydown="textCounter(this.form.txtmessage,this.form.ql_len,160);"
onkeyup="textCounter(this.form.txtmessage,this.form.ql_len,160);" runat="server" Width="200px"
CssClass="field" TextMode="MultiLine" Height="104px"></asp:textbox></TD>
</TR>
<TR bgColor="#bdd8e9">
<TD class="bottomline">Characters Remaining
<SPAN class="required"></SPAN>:</TD>
<TD class="bottomline"><INPUT class="field" id="ql_len" type="text" maxLength="16" value="160" name="ql_len"></TD>
</TR>
<TR>
<TD colspan="2" class="bottomline"><SPAN class="required">*</SPAN>
<SPAN class="comment">Required fields</SPAN>
</TD>
</TR>
<TR>
<TD align="right"><asp:Label ID="lblstatus" runat="server"></asp:Label>
<asp:button id="btnsubmit" runat="server" CssClass="button" Text=":: Send ::" onclick="btnsubmit_Click"></asp:button></TD>
<TD align="left">
<asp:button id="btnreset" runat="server" CssClass="button" Text=":: Reset ::" OnClick="btnreset_Click"></asp:button></TD>
</TR>
</TABLE>
</div>
</form>=====================================
.aspx.cs code -
protected void btnsubmit_Click(object sender, EventArgs e)
{
try
{
SendSmsManas.BLL.SMS.SendSMS(txtmobileno.Text, txtmessage.Text, ddlgateway.SelectedValue, txttitle.Text);
lblstatus.Text = "Message Sent";
}
catch (Exception Ex)
{
lblstatus.Text = Ex.Message;
}
}=======================================
BLL -
public static bool SendSMS(string MobileNo, string Message, string Port, string Sender)
{
string URL = DAL.Command.ExecuteScalar("SMSProvidersGetURL", CommandType.StoredProcedure, DAL.Parameter.SqlParameter("@ProviderPortID", Port)).ToString();
URL = URL.Replace("{0}", MobileNo);
URL = URL.Replace("{1}", Message);
URL = URL.Replace("{2}", Port);
URL = URL.Replace("{3}", Sender);
throw new Exception(URL);
//return true;
MobileNo = MobileNo.Trim();
string URL = DAL.Command.ExecuteScalar("SMSProvidersGetURL", CommandType.StoredProcedure, DAL.Parameter.SqlParameter("@ProviderPortID", Port)).ToString();
URL = URL.Replace("{0}", MobileNo);
//URL = URL.Replace("{1}", Message);
URL = URL.Replace("{1}", HttpContext.Current.Server.UrlEncode(Message));
URL = URL.Replace("{2}", Port);
URL = URL.Replace("{3}", Sender);
//System.Net.WebRequest WebRequest = System.Net.HttpWebRequest.Create("http://8.6.93.55/sms/php/transmitter.php?FinalMobile=" + MobileNo + "&SMSMSG=" + HttpContext.Current.Server.UrlEncode(Message) + "&PORT=" + Port);
System.Net.WebRequest WebRequest = System.Net.HttpWebRequest.Create(URL);
System.Net.WebResponse WebResponse = WebRequest.GetResponse();
System.IO.Stream s = WebResponse.GetResponseStream();
string res = (new System.IO.StreamReader(s)).ReadToEnd();
if (
res == "open status: open" ||
(res.Split('-')[0] == "The Message Id : " + MobileNo)
)
return true;
else
throw new Exception(res);
}====================================
DAL -
public object ExecuteScalar()
{
_comm.Connection.Open();
object val = _comm.ExecuteScalar();
_comm.Connection.Close();
return val;
}public static SqlConnection SqlConnection
{
get
{
string OraConnectionString;
//OraConnectionString = "Server=" + DBServer + "; database=" + DB + "; UID=" + DBUserID + ";Password=" + DBPassword;
OraConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
return new SqlConnection(OraConnectionString);
}
}
==================================
Friday, May 30, 2008 4:40 AM -
User-374796569 posted
hi
thank you for reply
i will check above code
Friday, May 30, 2008 6:30 AM