in frist web form that is SmsManager1 in that Mobile number, Search ,Send SMS and GridView is Design After clicking Send SMS button Second web form will open that is SmsManager2 in that Mobile Number ,TextBox For writing SMS with two Buttons that is Save and Send when we fill this Smsmanager2 form then Data will Display in the Gridview
Loading

Sarthak VarshneyRank #46 · 32K reputationPosted Jun 3, 2024, 1:12 PM EDT
To send an SMS to a mobile number in ASP.NET, you can use an SMS gateway API like Twilio. Below, I'll outline the steps and provide example code for creating two web forms,
SmsManager1andSmsManager2, and implementing the described functionality.Step 1: Create the ASP.NET Web Forms Project
Step 2: Design
SmsManager1Web FormSmsManager1.aspx, design the form with a GridView, a TextBox for the mobile number, and buttons for "Search" and "Send SMS".Step 3: Design
SmsManager2Web FormSmsManager2.aspx, design the form with a TextBox for the mobile number and another for the SMS content, along with "Save" and "Send" buttons.Step 4: Implement Code-Behind Logic
SmsManager1.aspx.cs
using System; using System.Web.UI; namespace YourNamespace { public partial class SmsManager1 : Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSearch_Click(object sender, EventArgs e) { // Implement search functionality here } protected void btnSendSMS_Click(object sender, EventArgs e) { // Redirect to SmsManager2 with the mobile number string mobileNumber = txtMobileNumber.Text; Response.Redirect($"SmsManager2.aspx?mobileNumber={mobileNumber}"); } } }SmsManager2.aspx.cs
using System; using System.Web.UI; using Twilio; using Twilio.Rest.Api.V2010.Account; namespace YourNamespace { public partial class SmsManager2 : Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string mobileNumber = Request.QueryString["mobileNumber"]; txtMobileNumber.Text = mobileNumber; } } protected void btnSave_Click(object sender, EventArgs e) { // Save the message to a database or other storage } protected void btnSend_Click(object sender, EventArgs e) { string mobileNumber = txtMobileNumber.Text; string message = txtMessage.Text; // Your Twilio credentials string accountSid = "your_account_sid"; string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var messageOptions = new CreateMessageOptions( new Twilio.Types.PhoneNumber(mobileNumber)) { From = new Twilio.Types.PhoneNumber("your_twilio_phone_number"), Body = message }; var msg = MessageResource.Create(messageOptions); // Optionally, save the message to a database and update the GridView } } }Step 5: Update GridView
SmsManager1, you can store the messages in a database and bind the GridView to the data source.// Example method to bind GridView private void BindGridView() { // Fetch messages from database and bind to GridView gvMessages.DataSource = GetMessagesFromDatabase(); gvMessages.DataBind(); } // Call this method in the Page_Load event or after sending/saving messages BindGridView();This example demonstrates the basic structure and logic for sending SMS from an ASP.NET Web Forms application using Twilio. Adjust the implementation as needed based on your specific requirements and data storage solutions.