zoukankan      html  css  js  c++  java
  • ASP.NET中用JS编写AJAX的编程实例

    //************测试页面

    <%@ Page Language="C#" MasterPageFile="~/Base/Eip.master" AutoEventWireup="true" CodeFile="text.aspx.cs" Inherits="Codinglog_text" Title="測試頁面" %>
    <%@ Register Assembly="RJS.Web.WebControl.PopCalendar.Ajax.Net" Namespace="RJS.Web.WebControl"
        TagPrefix="rjs" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <%@ Register Src="../Base/ContentLeft.ascx" TagName="ContentLeft" TagPrefix="uc3" %>
    <%@ Register Src="../Manage/UserControls/Page_Top.ascx" TagName="Page_Top" TagPrefix="uc1" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <script language="javascript" type="text/javascript" for="window" event="onload">
    <!--
    return window_onload()
    // -->
    </script>

    <script language="javascript" type="text/javascript">
    <!--

    function window_onload() {

    }

    var xmlhttp;
    function loadXMLDoc(url)
    {
    xmlhttp=null;
    if (window.XMLHttpRequest)
      {// code for Firefox, Opera, IE7, etc.
      xmlhttp=new XMLHttpRequest();
      }
    else if (window.ActiveXObject)
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    if (xmlhttp!=null)
      {
      xmlhttp.onreadystatechange=state_Change;
      xmlhttp.open("GET",url,true);
      xmlhttp.send(null);
      }
    else
      {
      alert("Your browser does not support XMLHTTP.");
      }
    }

    function state_Change()
    {
    if (xmlhttp.readyState==4)
      {// 4 = "loaded"
      if (xmlhttp.status==200)
        {// 200 = "OK"
        document.getElementById('Test1').innerHTML=xmlhttp.responseText;
        }
      else
        {
        alert("Problem retrieving data:" + xmlhttp.statusText);
        }
      }
    }


    function Button3_onclick() {
     loadXMLDoc("172.22.236.12/toptekeip/codinglog/ajaxrespond.ashx");
    }
    function Button4_onclick() {
     document.getElementById('Test1').innerHTML="";
    }

    function Text1_onkeydown() {
        var strtmp="";
        //alert("只能錄入數字!");
        if(event.keyCode==13)
        {
        strtmp= document.getElementById("Text1").value;
        loadXMLDoc("172.22.236.12/toptekeip/codinglog/ajaxrespond.ashx?reqkey=1&serial=" + strtmp);
        }
       
    }


    function Text1_onkeypress() {
        if(event.keyCode==48)
        { event.keyCode=0;
            //event.keycode.returnValue = false;
        alert("砂砂在");
       
        }
    }

    function Text1_onkeydown() {

    }

    // -->
    </script>

    <cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </cc1:ToolkitScriptManager>
        <table border="0" cellspacing="0" cellpadding="0" width="100%">
            <tr>
                <td style=" 20%; height: 211px;" valign="top">
                    <uc3:ContentLeft ID="ContentLeft1" runat="server" />
                </td>
                <td valign="top" style="height: 211px">
                    <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td style="height: 50px; ">
                            <uc1:Page_Top ID="Page_Top1" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 50px; 600px;">
                            &nbsp;<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                <ContentTemplate>
                                             
                            <asp:Label ID="Label1" runat="server" Text="我的測試菜單"></asp:Label>
                            <asp:Panel ID="Panel2" runat="server" Height="50px" Style="border-right: #666 1px solid;
                                        padding-right: 3px; border-top: #666 1px solid; padding-left: 3px; font-size: 12px;
                                        background: #ffffff; visibility: hidden; padding-bottom: 3px; border-left: #666 1px solid;
                                        line-height: 150%; padding-top: 3px; border-bottom: #666 1px solid" Width="160px">
                                <asp:LinkButton ID="LinkButton1" runat="server" Style="color: #000; font-size: 12px; text-decoration: none;">LinkButton</asp:LinkButton><br />
                                <asp:LinkButton ID="LinkButton2" runat="server" Style="color: #000; font-size: 12px; text-decoration: none;">LinkButton</asp:LinkButton>
                               </asp:Panel>
                                    &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<cc1:HoverMenuExtender ID="HoverMenuExtender1" runat="server"
                                        TargetControlID="Label1" PopupControlID="Panel2" PopupPosition="bottom" OffsetX="0" OffsetY="0" PopDelay="50">
                                    </cc1:HoverMenuExtender>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                <ContentTemplate>
                                    <asp:TextBox ID="txtMeetType" runat="server" Width="160px"></asp:TextBox>
                                    <asp:Panel ID="Panel1" runat="server" Height="50px" Style="border-right: #666 1px solid;
                                        padding-right: 3px; border-top: #666 1px solid; padding-left: 3px; font-size: 12px;
                                        background: #ffffff; visibility: hidden; padding-bottom: 3px; border-left: #666 1px solid;
                                        line-height: 150%; padding-top: 3px; border-bottom: #666 1px solid" Width="160px">
                                        <asp:Repeater ID="Repeater1" runat="server" >
                                            <ItemTemplate>
                                                <asp:LinkButton ID='MeetType' runat="server" CommandArgument='aaaa'
                                                    CommandName="Select" Style="color: #000; font-size: 12px; text-decoration: none;">sdsds</asp:LinkButton><br />
                                            </ItemTemplate>
                                        </asp:Repeater>
                                    </asp:Panel>
                                    <cc1:DropDownExtender ID="DropDownExtender1" runat="server" DropDownControlID="Panel1"
                                        TargetControlID="txtMeetType">
                                    </cc1:DropDownExtender>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                            &nbsp;&nbsp;&nbsp;
                            <br />
                            <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                <ContentTemplate>
                                    <cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="Panel3">
                                    </cc1:AnimationExtender>
                                    <asp:Panel ID="Panel3" runat="server" Height="50px" Width="125px">
                                        asdfasdfasdf</asp:Panel>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                            <br />

                        </td>
                    </tr>
                    <tr>
                        <td > &nbsp; &nbsp;&nbsp;
                            <asp:UpdatePanel ID="UpdatePanel4" runat="server">
                                <ContentTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" ReadOnly="True"></asp:TextBox>
                                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/GridSave.gif" />
                            <cc1:CalendarExtender ID="CalendarExtender1" runat="server"
                                TargetControlID="TextBox1" Format="yyyy-M-d" PopupButtonID="ImageButton1" SkinID="2">
                            </cc1:CalendarExtender>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                            &nbsp;
                            <asp:UpdatePanel ID="UpdatePanel5" runat="server">
                                <ContentTemplate>
                                    <cc1:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="Panel4" Opacity=".5" Rounded="true" TrackPosition="true">
                                    </cc1:DropShadowExtender>
                                    <asp:Panel ID="Panel4" runat="server" Height="50px" Width="125px" BackColor="#FFFFC0">
                                        dasdfasdasdfasdfasdfas</asp:Panel>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                        </td>
                    </tr>
                    <tr>
                        <td >
                        <asp:UpdatePanel ID="UpdatePanel6" runat="server">
                                <ContentTemplate>
                            <cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="LinkButton3" PopupControlID="Panel5" BackgroundCssClass="modalBackground" DropShadow="true" OkControlID="Button1"  CancelControlID="Button2">
                            </cc1:ModalPopupExtender>
                           
                            <asp:Panel ID="Panel5" runat="server" Height="93px" Width="232px" BackColor="White" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="1px">
                                fhjfgjfg<asp:Button ID="Button2" runat="server" Text="Button2" />
                                <asp:Button ID="Button1" runat="server" Text="Button1" />jhfgj</asp:Panel><asp:LinkButton ID="LinkButton3" runat="server">LinkButton</asp:LinkButton>
                                </ContentTemplate>
                            </asp:UpdatePanel>
                            &nbsp;
                           
                           
                        </td>
                    </tr>
                    <tr>
                        <td style="height: 20px; 572px;">
                            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                            <cc1:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server" TargetControlID="TextBox2" WatermarkText="請錄入姓名" WatermarkCssClass="watermarked">
                            </cc1:TextBoxWatermarkExtender>
                           
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input id="Button3" type="button" value="button" onclick="return Button3_onclick()" />
                            <input id="Button4" type="button" value="button" onclick="return Button4_onclick()" />
                            <input id="Text1" type="text" onkeypress="return Text1_onkeypress()" onkeydown="return Text1_onkeydown()" /></td>
                    </tr>
                    <tr>
                        <td >
                            <div id="Test1" style="border:1px solid #0000ff;">
                               
                            </div>
                            </td>
                    </tr>
                    <tr>
                        <td style="height: 20px; 572px;">
                            <table>
                                    <tr>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox9" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox10" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox11" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox12" runat="server"></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox13" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox14" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox15" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox16" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox17" runat="server"></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox18" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox19" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox20" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox21" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox22" runat="server"></asp:TextBox></td>
                                    </tr>
                                    <tr>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox23" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox24" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox25" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox26" runat="server"></asp:TextBox></td>
                                        <td style=" 100px">
                                            <asp:TextBox ID="TextBox27" runat="server"></asp:TextBox></td>
                                    </tr>
                                </table>
                             </td>
                    </tr>
                    <tr>
                        <td>
                           
                        </td>
                    </tr>
                    </table>
                </td>
            </tr>
        </table>  
       
    </asp:Content>

    //***********响应文件编写

    <%@ WebHandler Language="C#" class="AJAXRespond" %>

    using System;
    using System.Web;
    using System.Web.SessionState;
    using AMA.DB;
    using AMA.CommonComponent;
    using AMA.Pub;
    using Oracle.DataAccess.Client;
    using System.Data;

    public class AJAXRespond : IHttpHandler ,IReadOnlySessionState
    {
        OracleDB dbs = new OracleDB();
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            //context.Response.Write("Hello World");
            PubFuns.initSession();
            string strEmp = "";
            if (context.Request["reqkey"].ToString() == "1")
            {
                /*
                strEmp += "<table><tr><td>";
                strEmp += "<b>歡迎你</b>," + context.Session["EmpName"].ToString().Trim();
                strEmp += "</td></tr></table>";
                 * */
                if (context.Request["serial"] != null)
                {
                    //string ss = dbs.GetSingleData("select serial_number from emesp.sn_wip_rec where serial_number='" + context.Request["serial"].ToString().Trim() + "'");
                    OracleConnection con = new OracleConnection();
                    con.ConnectionString = dbs.ConnectionString;
                    con.Open();
                    OracleCommand cmd = new OracleCommand("EMESC.PC_CHECK_SN", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                 
                   
                    cmd.Parameters.Clear();
                    OracleParameter DATA = new OracleParameter("DATA", OracleDbType.NVarchar2, 4000);
                    DATA.Direction = ParameterDirection.Input;
                    DATA.Value =  context.Request["serial"].ToString().Trim();
                    cmd.Parameters.Add(DATA);

                    OracleParameter RES = new OracleParameter("RES", OracleDbType.NVarchar2, 4000);
                    RES.Direction = ParameterDirection.Output;
                    cmd.Parameters.Add(RES);
                    cmd.ExecuteNonQuery();
                   
                    string ss = cmd.Parameters["RES"].Value.ToString();
                    cmd.Dispose();
                    con.Close();
                    strEmp += "<table><tr><td>";
                    strEmp += "<b>歡迎你</b>," + ss;
                    strEmp += "</td></tr></table>";
                }
                else
                {
                    strEmp = "返回為空!";
               
                }
            }

            context.Response.Write(strEmp);
        
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }

    }

  • 相关阅读:
    [北大机试C]:走迷宫(BFS)
    [北大机试B][OpenJ_Bailian-2965]:玛雅历(模拟)
    [北大机试A]:有趣的跳跃(模拟)
    [2019北大机试D]:最大上升子序列和(DP)[计蒜客-T1221/HDU1087]
    [牛客练习赛53] A.超越学姐爱字符串 [dp]
    [牛客][北大考研复试]I Wanna Go Home[dijkstra]
    SP1716 GSS3
    牛客小白月赛13_A_小A的签到题
    自习室管理系统,基于B/S模式下的JAVA系统
    基于SSH的聊天室
  • 原文地址:https://www.cnblogs.com/vic_lu/p/1810086.html
Copyright © 2011-2022 走看看