API Demonstration ASP.NET

Category > ASP.NET || Published on : Friday, February 19, 2016 || Views: 19076 || API Demonstration ASP.NET API Demonstration


Introduction

Here Pawan Kumar will explain how to API Demonstration ASP.NET

Description

In previous post I have explained Show Hide Password Using Javascript ASP.NET, How to Create Tab Control Using jQuery In Asp.Net, jQuery Datepicker Calendar With Slide Down Effect In Asp.Net, jQuery Code To Select Multiple Item By Pressing Ctrl Button In Asp.Net, How to bind dropdown list with XML file in asp.net?, Validate ASP.Net form using CSS in C#, and many more articles.

Now I will explain How to API Demonstration ASP.NET

So follow the steps to learn API Demonstration ASP.NET

API Demonstration ASP.NET

ASPX Code:-

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <h1 align="center">API Demonstration ASP.NET </h1>
   
    <table align="center"width="400px">
   
    <tr  >
    <td width="50%">
        <asp:Label ID="lblUid" runat="server" Text="Uid"></asp:Label>
    
    </td>
    <td width="50%">
        <asp:TextBox ID="txtUid" runat="server" Width="200px"></asp:TextBox>
    
    </td>
    </tr>
    <tr  >
    <td width="50%">
        <asp:Label ID="lblPin" runat="server" Text="Pin"></asp:Label>
    
    </td >
    <td width="50%">
        <asp:TextBox ID="txtPin" runat="server" TextMode="Password" Width="200px"></asp:TextBox>
    
    </td>
    </tr>
    <tr>
    <td width="50%">
    
        <asp:Label ID="lblDomain" runat="server" Text="DomainName"></asp:Label>
    </td>
    <td width="50%">
        <asp:TextBox ID="txtDomain" runat="server" Width="200px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td width="50%">
    
        <asp:Label ID="lblSenderId" runat="server" Text="Valid SenderId"></asp:Label>
    </td>
    <td width="50%">
        <asp:TextBox ID="txtSenderId" runat="server" Width="197px"></asp:TextBox>
    </td>
    </tr>
    <tr>
      
    <td width="50%">
      <asp:Label ID="lblMobile" runat="server" Text="Mobile"></asp:Label>
    </td>
    <td width="50%">
       <asp:TextBox ID="txtMobile" runat="server" Width="200px"></asp:TextBox>
    </td>
    </tr>
    
      <td width="50%">
      <asp:Label ID="lblRoute" runat="server" Text="Route"></asp:Label>
    </td>
    <td width="50%">
       <asp:TextBox ID="txtRoute" runat="server" Width="200px"></asp:TextBox> 
       (0 Normal 1 Priority )
    </td>
    </tr>
       
    <tr>
    <td width="50%">
    
        <asp:Label ID="lblMessage" runat="server" Text="Message"></asp:Label>
    </td>
    <td width="50%">
        <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Width="200px"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td width="50%">
    
     
    </td>
        
    <td width="50%">
    <table>
    <tr>
    <td>
       <asp:Button ID="btnSend" runat="server" Text="Send" onclick="btnSend_Click" 
            Width="56px" />
    </td>
    &nbsp;&nbsp;
    <td>
     <asp:Button ID="btnClear" runat="server" Text="Clear"  
            Width="56px" onclick="btnClear_Click" />
    </td>
    </tr>
    </table>
 
    </td>
    
    </tr>
    </table>
   
    </form>
</body>
</html>

Code Behind:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public string mobile
    {
        get;
        set;
    }
    public string message
    {
        get;
        set;
    }
    public string uid
    {
        get;
        set;
    }
    public string pin
    {
        get;
        set;
    }
    public string domian
    {
        get;
        set;
    }
	   public string route
    {
        get;
        set;
    }
    public string sender
    {
        get;
        set;
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        try
        {
            mobile = txtMobile.Text;
            message = txtMessage.Text;
            uid = txtUid.Text;
            pin = txtPin.Text;
            sender = txtSenderId.Text;
            domian = txtDomain.Text;
			route = txtRoute.Text;
            string result = apicall("http://" + domian + "/api/sms.php?uid=" + uid + "&pin=" + pin + "&sender=" + sender + "&route=" + route + "&mobile=" + mobile + "&message=" + message);
			
			
			
            if (!result.StartsWith("Wrong Username or Password"))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sent')", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sending Failed')", true);
            }
               
        }
        catch
        {
        }
    }
    public string apicall(string url)
    {
        HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(url);

        try
        {

            HttpWebResponse httpres = (HttpWebResponse)httpreq.GetResponse();

            StreamReader sr = new StreamReader(httpres.GetResponseStream());

            string results = sr.ReadToEnd();

            sr.Close();
            return results;



        }
        catch
        {
            return "0";
        }
    }
    protected void btnClear_Click(object sender, EventArgs e)
    {
        txtUid.Text="";
        txtPin.Text = "";
        txtDomain.Text = "";
        txtSenderId.Text = "";
        txtMobile.Text = "";
		txtRoute.Text = "";
        txtMessage.Text = "";
    }
}

 

Conclusion:

So, In this tutorial we have learned, API Demonstration ASP.NET

Download Source Codes