• ajaxpro实现无刷新更新数据库【简单方法】


    原文发布时间为:2008-10-24 —— 来源于本人的百度文章 [由搬家工具导入]

    我用的是AjaxPro.2.dll,然后我想点击那个 “无刷新更新” 那个按钮,实现 无刷新 修改表中的内容

    HTML code
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!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> <script type="text/javascript"> function gx() { var u=document.getElementById("TextBox1").value; var p=document.getElementById("TextBox2").value; var s=document.getElementById("TextBox3").value; Default2.gengxin(u,p,s,callback); } function callback(res) { if(res.value==true)
          {
              alert('提交成功');         
              document.getElementById("Button2").disabled=false;
              document.getElementById("Button2").value="无刷新更新";
       }
          } </script></head><body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <br /> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /> <br /> <asp:TextBox ID="TextBox3" runat="server" OnTextChanged="TextBox3_TextChanged"></asp:TextBox><br /> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="普通更新" /><br /> <br />         &nbsp;<input id="Button2" type="button" value="无刷新更新" onclick="this.disabled=true;this.value='正在提交当中';return gx()"/></div>
    </form></body></html>
    C# code
    using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;using AjaxPro;public partial class Default2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { AjaxPro.Utility.RegisterTypeForAjax(typeof(Default2)); } [AjaxPro.AjaxMethod] public bool gengxin(string u,string p,string s) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["testConn"].ConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand("Proc_UpdateTest", conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] param = new SqlParameter[3]; param[0] = new SqlParameter("@user", SqlDbType.NChar, 10); param[0].Value = u; param[1] = new SqlParameter("@paper", SqlDbType.NChar, 10); param[1].Value = p; param[2] = new SqlParameter("@score", SqlDbType.NChar, 10); param[2].Value = s; foreach (SqlParameter Parameter in param) cmd.Parameters.Add(Parameter); cmd.ExecuteNonQuery(); //SqlCommand cmd = new SqlCommand("update Paper set paper='" +p + "',score='" + s+"' where user='" +u + "'",conn); //cmd.ExecuteNonQuery(); conn.Close(); return true; } protected void Button1_Click(object sender, EventArgs e) { gengxin(TextBox1.Text,TextBox2.Text,TextBox3.Text); } protected void TextBox3_TextChanged(object sender, EventArgs e) { }}
  • 相关阅读:
    Android OpenGL ES 2.0 (四) 灯光perfragment lighting
    Android OpenGL ES 2.0 (五) 添加材质
    冒泡排序函数
    javascript object 转换为 json格式 toJSONString
    Liunx CentOS 下载地址
    jquery 图片切换特效 鼠标点击左右按钮焦点图切换滚动
    javascript 解析csv 的function
    mysql Innodb Shutdown completed; log sequence number解决办法
    Centos 添加 yum
    javascript 键值转换
  • 原文地址:https://www.cnblogs.com/handboy/p/7141604.html
Copyright © 2020-2023  润新知