Send multiple SMS on single Button Click in ASP.Net

indradeo
 
on Aug 02, 2022 12:32 AM
557 Views

Dear sir,

how to send two sms of single button click.

i want to send sms customer and client both sms. but while i have click on submit button then only one sms sent to customer side. Client side sms not done.

how to do this?

namespace OCMS
{
    public partial class It_Comp : System.Web.UI.Page
    {
        string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        string strrr;
        SqlCommand com;
        int count;
        protected void Page_Load(object sender, EventArgs e)
        {           
            string IPAdd = string.Empty;
            IPAdd = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(IPAdd))
                IPAdd = Request.ServerVariables["REMOTE_ADDR"];
            lblIP.Text = IPAdd;
            if (!Page.IsPostBack)
            {
                ReadOnlyTextBox.Text = "IT COMPLAINT";
                lblName.Text = " " + Request.QueryString["EmpId"] + "";
                BindGrid();
                this.StoreVisitorIPDetails();
            }

            if (!this.IsPostBack)
            {
                Label1.Text = Request.QueryString["EmpId"];

                string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                using (SqlConnection con = new SqlConnection(conString))
                {
                    using (SqlCommand cmd = new SqlCommand("SELECT PHONE_MOB FROM emp WHERE EMP_ID=@Id", con))
                    {
                        cmd.Parameters.AddWithValue("@Id", Label1.Text);
                        con.Open();
                        Label1.Text = Convert.ToString(cmd.ExecuteScalar());
                        con.Close();
                    }
                }
            }
            //LabelD.Text = DateTime.Now.ToShortDateString();
            LabelD.Text = DateTime.Now.ToString("dd/MMM/yyyy");
        }
            
        private void StoreVisitorIPDetails()
        {
            string employeeId = lblName.Text.Trim();
            string ipAddress;
            // Gets Client IP Address
            ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (ipAddress == "" || ipAddress == null)
                ipAddress = Request.ServerVariables["REMOTE_ADDR"];

            string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnString);

            SqlCommand cmd = new SqlCommand("StoreIPAddressDetails");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@IPAddress", ipAddress);
            cmd.Parameters.AddWithValue("@EMP_ID", employeeId);
            cmd.Connection = con;
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            con.Dispose();
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("Index.aspx?EmpId=" + lblName.Text.Trim());
        }
        protected void Button1_Click(object sender, EventArgs e)
        {            
            string employeeId = lblName.Text.Trim();
            string message = str.Text.Trim();
            string ReadOnly = ReadOnlyTextBox.Text.Trim();
            string COMP_LODGE_DATE = DateTime.Now.ToString("yyy/dd/mm");
            string image = "";
            if (FileUpload1.HasFile)
            {
                string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                if (!Directory.Exists(Server.MapPath("~/Images")))
                {
                    Directory.CreateDirectory(Server.MapPath("~/Images"));
                }
                FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Images/") + fileName);
                image = "~/Images/" + fileName;
            }
            string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
            string query = "insert_ittest1";
            using (SqlConnection con = new SqlConnection(conString))
            {
                SqlCommand cmd = new SqlCommand(query);
                cmd.Parameters.AddWithValue("@EMP_ID", employeeId);
                cmd.Parameters.AddWithValue("@COMP_MESSAGE", message);
                cmd.Parameters.AddWithValue("@Comp_type", ReadOnly);
                cmd.Parameters.AddWithValue("@COMP_LODGE_DATE", COMP_LODGE_DATE);
                cmd.Parameters.AddWithValue("@image", image);
                cmd.Parameters.Add("@COMP_ID", SqlDbType.Int).Direction = ParameterDirection.Output; 
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Connection = con;
                try
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    string COMP_ID = cmd.Parameters["@COMP_ID"].Value.ToString();
                   // string COMP_LODGE_DATE = DateTime.Now.ToString();
                    txtrowid.Text = "" + COMP_ID;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {                    
                    con.Close();
                    con.Dispose();
                }

                string comp = txtrowid.Text;
                string Date = LabelD.Text;
                string mob = Label1.Text;
                string empid = lblName.Text;
               
                string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&from=MUNPLA&to=" + mob + ".&text=Thanks for using OCMS . Your Complaint number is :-" + comp + ".We will  resolve  shortly. - Meja Urja Nigam PVT. LTD &indiaDltContentTemplateId=1207164482155108999&indiaDltPrincipalEntityId=1201159222154902387";
                // string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&from=MUNPLA&to=" + mob + ".&text=Thanks for using OCMS . Your Complaint number is :- " + comp + ". we have attend shortly. date " + Date + "'&indiaDltContentTemplateId=1207164257090367117&indiaDltPrincipalEntityId=1201159222154902387";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SMSurl);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream());
                Response.Redirect(Request.Url.AbsoluteUri);
                clientsms();
            }
        }

        private void clientsms()
        {
            string comp1 = txtrowid.Text;
            string Date1 = LabelD.Text;
            string mob1 = Label1.Text;
            string empid1 = lblName.Text;

            string SMSurl1 = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&to=919667044472,919990299123,919989431343.&text=' Complaints has been raised by  " + empid1 + " with complaints number :" + comp1 + " Date1" + Date1 + "'  - Meja Urja Nigam PVT. Ltd&from=MUNPLA&indiaDltContentTemplateId=1207161744345584585&indiaDltPrincipalEntityId=1201159222154902387";
            HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(SMSurl1);
            HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
            StreamReader sr1 = new StreamReader(response1.GetResponseStream());
            Response.Redirect(Request.Url.AbsoluteUri);
        }
    }
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
PrinceG
 
on Aug 02, 2022 02:01 AM
on Aug 02, 2022 02:03 AM
indradeo says:
string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&from=MUNPLA&to=" + mob + ".&text=Thanks for using OCMS . Your Complaint number is :-" + comp + ".We will  resolve  shortly. - Meja Urja Nigam PVT. LTD &indiaDltContentTemplateId=1207164482155108999&indiaDltPrincipalEntityId=1201159222154902387";
               // string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&from=MUNPLA&to=" + mob + ".&text=Thanks for using OCMS . Your Complaint number is :- " + comp + ". we have attend shortly. date " + Date + "'&indiaDltContentTemplateId=1207164257090367117&indiaDltPrincipalEntityId=1201159222154902387";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SMSurl);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream());
                Response.Redirect(Request.Url.AbsoluteUri);
                clientsms();

Please replace above code with below modified code.

As you are redirecting using Response.Redirect in clientsms method, you does not need to redirect on button1_click event.

You only need to call the method in button1_click event.

 string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&from=MUNPLA&to=" + mob + ".&text=Thanks for using OCMS . Your Complaint number is :-" + comp + ".We will  resolve  shortly. - Meja Urja Nigam PVT. LTD &indiaDltContentTemplateId=1207164482155108999&indiaDltPrincipalEntityId=1201159222154902387";
 // string SMSurl = "http://185.255.8.59/sms/1/text/query?username=NTpc&password=NTpc@321&from=MUNPLA&to=" + mob + ".&text=Thanks for using OCMS . Your Complaint number is :- " + comp + ". we have attend shortly. date " + Date + "'&indiaDltContentTemplateId=1207164257090367117&indiaDltPrincipalEntityId=1201159222154902387";
 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(SMSurl);
 HttpWebResponse response = (HttpWebResponse)request.GetResponse();
 StreamReader sr = new StreamReader(response.GetResponseStream());
 clientsms();