метод GET

 
 

синтаксис

http://хост/путь?параметр=значение&параметр=значение
 
 

реализация метода GET вручную

В данном примере, пользователь должен самостоятельно ввести GET запрос, например ?a=50&=100
Скрыть

Показать

Копировать
  Default.aspx  
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <meta charset="utf-8" />
 <title></title>
</head>
<body>
 <form id="form1" runat="server">
  <!--блок изначально не видим-->
  <div id="div1" runat="server" visible="false">
   <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
   &nbsp;&nbsp;
   +
   &nbsp;&nbsp;
   <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
   &nbsp;&nbsp;
   =
   &nbsp;&nbsp;
   <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
  </div>
 </form>
</body>
</html>
Скрыть

Показать

Копировать
  Default.aspx.cs  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI.Page {
 int Result(string arg0, string arg1) {
  int a = int.Parse(arg0);
  int b = int.Parse(arg1);
  return (a + b);
 }
 protected void Page_Load(object sender, EventArgs e) {
  string a = Request.QueryString["a"];
  string b = Request.QueryString["b"];
  if(Request.HttpMethod == "GET") {
   //если значения параметров метода GET пустые
   if(string.IsNullOrEmpty(a) & string.IsNullOrEmpty(b)) {
    //блок с расчетом не видимый
    div1.Visible = false;
   }
   else {
    //блок с расчетом видимый
    div1.Visible = true;
    Label1.Text = a;
    Label2.Text = b;
    Label3.Text = Result(Label1.Text, Label2.Text).ToString();
   }
  }
 }
}
 
 

реализация метода GET с помощью ссылки

Скрыть

Показать

Копировать
  Default.aspx  
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <meta charset="utf-8" />
 <title></title>
</head>
<body>
 <form id="form1" runat="server">
  <a id="go" runat="server" href="Default.aspx?a=10&b=20">GO</a>
  <!--ссылка изначально не видимая-->
  <a id="back" runat="server" visible="false" href="Default.aspx?a=&b=">BACK</a>
  <br />
  <br />
  <!--блок изначально не видим-->
  <div id="div1" runat="server" visible="false">
   <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
   &nbsp;&nbsp;
   +
   &nbsp;&nbsp;
   <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
   &nbsp;&nbsp;
   =
   &nbsp;&nbsp;
   <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
  </div>
 </form>
</body>
</html>
Скрыть

Показать

Копировать
  Default.aspx.cs  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI.Page {
 int Result(string arg0, string arg1) {
  int a = int.Parse(arg0);
  int b = int.Parse(arg1);
  return (a + b);
 }
 protected void Page_Load(object sender, EventArgs e) {
  string a = Request.QueryString["a"];
  string b = Request.QueryString["b"];
  if(Request.HttpMethod == "GET") {
   //если значения параметров метода GET пустые
   if(string.IsNullOrEmpty(a) & string.IsNullOrEmpty(b)) {
    //ссылка GO видимая
    go.Visible = true;
    //ссылка BACK не видимая
    back.Visible = false;
    //блок с расчетом не видимый
    div1.Visible = false;
   }
   else {
    //ссылка GO не видимая
    go.Visible = false;
    //ссылка BACK видимая
    back.Visible = true;
    //блок с расчетом видимый
    div1.Visible = true;
    Label1.Text = a;
    Label2.Text = b;
    Label3.Text = Result(Label1.Text, Label2.Text).ToString();
   }
  }
 }
}
 
 

реализация метода GET с помощью формы

Скрыть

Показать

Копировать
  Default.aspx  
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <meta charset="utf-8" />
 <title></title>
</head>
<body>
 <form action="Default.aspx" method="get">
  <input type="text" name="a" />
  <br />
  <br />
  <input type="text" name="b" />
  <br />
  <br />
  <input type="submit" name="go" value="GO" />
 </form>
 <br />
 <br />
 <form id="form1" runat="server">
  <!--блок изначально не видим-->
  <div id="div1" runat="server" visible="false">
   <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
   &nbsp;&nbsp;
   +
   &nbsp;&nbsp;
   <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
   &nbsp;&nbsp;
   =
   &nbsp;&nbsp;
   <asp:Label ID="Label3" runat="server" Text=""></asp:Label>
  </div>
 </form>
</body>
</html>
Скрыть

Показать

Копировать
  Default.aspx.cs  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI.Page {
 int Result(string arg0, string arg1) {
  int a = int.Parse(arg0);
  int b = int.Parse(arg1);
  return (a + b);
 }
 protected void Page_Load(object sender, EventArgs e) {
  string a = Request.QueryString["a"];
  string b = Request.QueryString["b"];
  if(Request.HttpMethod == "GET") {
   //если была нажата кнопка GO
   if(Request["go"] != null) {
    //если значения параметров метода GET пустые
    if(string.IsNullOrEmpty(a) & string.IsNullOrEmpty(b)) {
     //блок с расчетом не видимый
     div1.Visible = false;
    }
    else {
     //блок с расчетом видимый
     div1.Visible = true;
     Label1.Text = a;
     Label2.Text = b;
     Label3.Text = Result(Label1.Text, Label2.Text).ToString();
    }
   }
  }
 }
}
 
 

слайдер

Скрыть

Показать

Копировать
  Default.aspx  
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <meta charset="utf-8" />
 <link href="css/style.css" rel="stylesheet" />
 <title></title>
</head>
<body>
 <form id="form1" runat="server">
  <div class="main">
   <div class="left">
    <div>
     <%
      for(int i=0; i<10; ) {
       i++;
       if(i == 10) {
        Response.Write("&nbsp;&nbsp;<a href=\"Default.aspx?a="+i+"\">фото "+i+"</a><br />");
       }
       else {
        Response.Write("<a href=\"Default.aspx?a="+i+"\">фото "+i+"</a><br />");
       }
      }
     %>
    </div>
   </div>
   <div class="right">
    <div>
     <%
      string a = Request.QueryString["a"];
      if(Request.HttpMethod == "GET") {
       //если значения параметров метода GET пустые
       if(string.IsNullOrEmpty(a)) {
        Response.Write("");
       }
       else {
        //если значение вне диапазона
        if(int.Parse(a)<1 | int.Parse(a)>10) {
         a = "1";
        }
        Response.Write("<img src=\"img/"+a+".png\" />");
       }
      }
     %>
    </div>
   </div>
  </div>
 </form>
</body>
</html>
Скрыть

Показать

Копировать
  css/style.css  
* {
 margin: 0;
 padding: 0;
}
 
.main {
 height: 598px;
 width: 998px;
 position: absolute;
 top: 50%;
 left: 50%;
 margin-top: -300px;
 margin-left: -500px;
 border: 1px solid #FFDD00;
}
 
.left {
 height: 598px;
 width: 397px;
 border-right: 1px solid #FFDD00;
 float:left;
 font-size: 36px;
 text-align: center;
 display: table;
 background-color: #F2F2F2;
}
 
.left>div {
 display: table-cell;
 vertical-align: middle;
}
 
.left>div>a {
 text-decoration: none;
}
 
.right {
 height: 598px;
 width: 600px;
 float:left;
 background-color: #F2F2F2;
}
 
.right>div {
 height: 400px;
 width: 250px;
 position: relative;
 top: 50%;
 left: 50%;
 margin-top: -200px;
 margin-left: -125px;
}
 
 

выбор товара из базы данных

Скрыть

Показать

Копировать
  Default.aspx  
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_0005_db.Default" %>
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <meta charset="utf-8" />
 <link href="css/style.css" rel="stylesheet" />
 <title></title>
</head>
<body>
 <form id="form1" runat="server">
  <div class="main">
   <div class="left">
    <div>
     <% Function1(); %>
    </div>
   </div>
   <div class="center">
    <div class="a">
     <div class="caption">Name</div>
     <div class="info">
      <% Function2("Name"); %>
     </div>
    </div>
    <p></p>
    <div class="a">
     <div class="caption">Amount</div>
     <div class="info">
      <% Function2("Amount"); %>
     </div>
    </div>
    <p></p>
    <div class="a">
     <div class="caption">Price</div>
     <div class="info">
      <% Function2("Price"); %>
     </div>
    </div>
   </div>
   <div class="right">
    <div>
     <% Function3(); %>
    </div>
   </div>
  </div>
 </form>
</body>
</html>
Скрыть

Показать

Копировать
  Default.aspx.cs  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using System.Data;
using System.Data.SqlClient;
//подключить пространство имен
using System.Configuration;
 
namespace _0005_db {
 public partial class Default : System.Web.UI.Page {
  int counter = 0;
  public void Function1() {
   string stringConnect = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
   string sql = "SELECT ID, Name, Amount, Price, Image FROM Alco";
   using(SqlConnection connect = new SqlConnection(stringConnect)) {
    connect.Open();
    SqlCommand cmd = new SqlCommand(sql, connect);
    SqlDataReader reader = cmd.ExecuteReader();
    //int counter = 0;
    while(reader.Read()) {
     counter++;
     if(counter < 10) {
      Response.Write(reader.GetInt32(0)+"&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"Default.aspx?a="+reader.GetInt32(0)+"\">"+reader.GetString(1)+"</a><br />");
     }
     else if(counter>9 & counter<100) {
      Response.Write(reader.GetInt32(0)+"&nbsp;&nbsp;<a href=\"Default.aspx?a="+reader.GetInt32(0)+"\">"+reader.GetString(1)+"</a><br />");
     }
    }
   }
  }
  public void Function2(string arg) {
   string a = Request.QueryString["a"];
   int id = 0;
   if(Request.HttpMethod == "GET") {
    //если значения параметров метода GET пустые
    if(string.IsNullOrEmpty(a)) {
     Response.Write("");
    }
    else {
     //если значение вне диапазона
     if(int.Parse(a)<1 | int.Parse(a)>counter) {
      id = 1;
     }
     else {
      id = int.Parse(a);
     }
    }
   }
 
   string stringConnect = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
   using(SqlConnection connect = new SqlConnection(stringConnect)) {
    connect.Open();
    if(arg == "Name") {
     string sql = "SELECT Name FROM Alco WHERE ID="+id+"";
     SqlCommand cmd = new SqlCommand(sql, connect);
     SqlDataReader reader = cmd.ExecuteReader();
     while(reader.Read()) {
      Response.Write(reader.GetString(0));
     }
    }
    else if(arg == "Amount") {
     string sql = "SELECT Amount FROM Alco WHERE ID="+id+"";
     SqlCommand cmd = new SqlCommand(sql, connect);
     SqlDataReader reader = cmd.ExecuteReader();
     while(reader.Read()) {
      Response.Write(reader.GetInt32(0));
     }
    }
    else if(arg == "Price") {
     string sql = "SELECT Price FROM Alco WHERE ID="+id+"";
     SqlCommand cmd = new SqlCommand(sql, connect);
     SqlDataReader reader = cmd.ExecuteReader();
     while(reader.Read()) {
      Response.Write(Math.Round(reader.GetDecimal(0), 2));
     }
    }
   }
  }
  public void Function3() {
   string a = Request.QueryString["a"];
   int id = 0;
   if(Request.HttpMethod == "GET") {
    //если значения параметров метода GET пустые
    if(string.IsNullOrEmpty(a)) {
     Response.Write("");
    }
    else {
     //если значение вне диапазона
     if(int.Parse(a)<1 | int.Parse(a)>counter) {
      id = 1;
     }
     else {
      id = int.Parse(a);
     }
    }
   }
 
   byte[] byteArray = new byte[0];
   string stringConnect = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
   using(SqlConnection connect = new SqlConnection(stringConnect)) {
    connect.Open();
    string sql = "SELECT Image FROM Alco WHERE ID="+id+"";
    SqlCommand cmd = new SqlCommand(sql, connect);
    SqlDataReader reader = cmd.ExecuteReader();
    while(reader.Read()) {
     byteArray = new byte[((byte[])reader["Image"]).Length];
     byteArray = (byte[])reader["Image"];
     string base64String;
     base64String = System.Convert.ToBase64String(byteArray, 0, byteArray.Length);
     Response.Write("<img src=\"data:image/png;base64,"+base64String+"\" width=\"250\" height=\"400\" />");
    }
   }
  }
  protected void Page_Load(object sender, EventArgs e) {
 
  }
 }
}
Скрыть

Показать

Копировать
  css/style.css  
* {
 margin: 0;
 padding: 0;
}
 
.main {
 height: 598px;
 width: 998px;
 position: absolute;
 top: 50%;
 left: 50%;
 margin-top: -300px;
 margin-left: -500px;
 border: 1px solid #1378C0;
 border-radius: 20px;
}
 
.left {
 height: 598px;
 width: 299px;
 float:left;
 font-size: 26px;
 text-align: left;
 background-color: #F0FAFF; 
 overflow-y: auto;
 border-top-left-radius: 20px;
 border-bottom-left-radius: 20px;
}
 
.left>div {
 padding: 25px 0 25px 25px;
}
 
.left>div>a {
 text-decoration: none;
}
 
.center {
 height: 598px;
 width: 297px;
 border-left: 1px solid #1378C0;
 border-right: 1px solid #1378C0;
 float:left;
}
 
.a {
 height: 198.6666px;
 width: 297px;
 background-color: #F2F2F2;
}
 
.center>p {
 height: 1px;
 width: 297px;
 background-color:#1378C0;
}
 
.caption {
 height: 48.6666px;
 width: 297px;
 color: #ffffff;
 font-size: 26px;
 background-color: #1378C0;
 text-align: center;
 line-height: 48.6666px;
}
 
.info {
 height: 150px;
 width: 297px;
 background-color: #ffffff;
 font-size: 22px;
 text-align: center;
 line-height: 150px;
 overflow: auto;
}
 
.right {
 height: 598px;
 width: 400px;
 float: left;
 background-color: #F0FAFF;
 border-top-right-radius: 20px;
 border-bottom-right-radius: 20px;
}
 
.right>div {
 height: 400px;
 width: 250px;
 position: relative;
 top: 50%;
 left: 50%;
 margin-top: -200px;
 margin-left: -125px;
}