濮阳杆衣贸易有限公司

主頁 > 知識庫 > ajax 服務(wù)器文本框自動(dòng)填值

ajax 服務(wù)器文本框自動(dòng)填值

熱門標(biāo)簽:姜堰電銷機(jī)器人 海南銀行智能外呼系統(tǒng)商家 澳大利亞城市地圖標(biāo)注 許昌智能電銷機(jī)器人公司 電銷機(jī)器人違法了嗎 遼寧銀行智能外呼系統(tǒng) 上海浦東騰訊地圖標(biāo)注位置 辰溪地圖標(biāo)注 遼寧正規(guī)電銷機(jī)器人
這樣的話就增加了服務(wù)器的負(fù)擔(dān)。后面自己他細(xì)想了一下。想利用ajax去實(shí)現(xiàn)這樣一個(gè)效果。代碼如下:
前臺代碼:
復(fù)制代碼 代碼如下:

%@ Page Language="C#" AutoEventWireup="true" CodeFile="ServerTextBoxdata.aspx.cs" Inherits="Default3" %>
!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>通過用戶名自動(dòng)填充用戶其他信息/title>
script language="javascript" type="text/javascript" src="ajax/jquery.js">/script>
script language="javascript" type="text/javascript">
//獲取用戶名文本框的值
function WritedataText()
{
var username=$("#Txtusename").val();
if(username.length==0)
{
alert("輸入的用戶名不能為空");
return ;
}
//執(zhí)行通過用戶名查找用戶的相關(guān)信息
$.ajax({
type:'POST',
url:'ServerTextBoxdata.aspx',
data:{action:'action',Username:username},
success:WritedataTextcallback
})
}
//通過用戶名查找用戶的相關(guān)信息的回調(diào)函數(shù)
function WritedataTextcallback(r)
{
if(r=="no")
{
alert("輸入的用戶名不存在。請重新輸入");
}
else
{
var data=r;
var array=new Array();
array=data.split(",");
//為文本框賦值
$("#fullname").val(array[0]);
$("#Email").val(array[1]);
$("#mobilphone").val(array[2]);
$("#qq").val(array[3]);
}
}
/script>
/head>
body>
form id="form1" runat="server">
div align="center">
table style="text-align:center;width:800px">
tr style=" background-color:Yellow; width:800px">
td colspan='2' style="text-align:center"> font size="5" color="red">用戶詳細(xì)信息/font>/td>
/tr>
tr>td colspan='2' style=" text-align:left"> 用戶名稱:asp:TextBox ID="Txtusename" runat="server">/asp:TextBox>/td>/tr>
tr>td style=" text-align:left;width:400px"> 用戶全名:asp:TextBox ID="fullname" runat="server" ReadOnly="true">/asp:TextBox>/td>td style=" text-align:left; width:400px">用戶郵箱:asp:TextBox ID="Email" ReadOnly="true" runat="server">/asp:TextBox>/td>/tr>
tr>td style=" text-align:left;width:400px">手機(jī)號碼:asp:TextBox runat="server" ID="mobilphone" ReadOnly="true">/asp:TextBox>/td>td style=" text-align:left; width:400px">
用戶QQ nbsp;:asp:TextBox runat="server" ID="qq" ReadOnly="true">/asp:TextBox>/td>/tr>
/table>
/div>
/form>
/body>
/html>

后臺代碼:
復(fù)制代碼 代碼如下:

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;
public partial class Default3 : System.Web.UI.Page
{
string StrAction = "";
protected void Page_Load(object sender, EventArgs e)
{
StrAction = Request["action"];
//為服務(wù)器控件添加失去焦點(diǎn)的事件 讓服務(wù)器控件不刷新的關(guān)鍵
Txtusename.Attributes.Add("onblur", "WritedataText()");
Txtusename.Focus();
if (StrAction == "action")
{
//獲取用戶輸入的名稱
string username = Request["Username"];
if (!Isusername(username))
{
Response.Clear();
Response.ContentType = "application/text";
Response.Write("no");
Response.End();
}
else
{
InitData(username);
}
}
}
/// summary>
/// 創(chuàng)建人:周昕
/// 創(chuàng)建時(shí)間:2009-06-11
/// 方法名稱:InitData
/// 作用:查找用戶的詳細(xì)信息
/// /summary>
/// param name="username">/param>
public void InitData(string username)
{
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["BoBoConn"].ToString();
string sql = "select Fullname,Email,MobilePhone,QQ from loginuser where username='"+username+"'";
mycon.Open();
SqlCommand mycom = new SqlCommand(sql, mycon);
SqlDataReader myda = mycom.ExecuteReader();
while (myda.Read())
{
string fullname = myda["Fullname"].ToString();
string Email = myda["Email"].ToString();
string MobilePhone = myda["MobilePhone"].ToString();
string QQ = myda["QQ"].ToString();
string array = fullname + "," + Email + "," + MobilePhone+","+QQ;
Response.Clear();
Response.ContentType = "application/text";
Response.Write(array);
Response.End();
}
}
/// summary>
/// 創(chuàng)建人:周昕
/// 創(chuàng)建時(shí)間:2009-06-11
/// 方法名稱:Isusername
/// 作用:返回bool值判斷用戶是否存在
/// /summary>
/// param name="username">/param>
/// returns>/returns>
public bool Isusername(string username)
{
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["BoBoConn"].ToString();
string sql = "select count(*) from loginuser where username='" + username + "'";
mycon.Open();
SqlCommand mycom = new SqlCommand(sql, mycon);
int n = (int)mycom.ExecuteScalar();
mycon.Close();
if (n > 0)
{
return true;
}
else
{
return false;
}
}
}

效果:運(yùn)行前只有用戶名文本框可用

當(dāng)用戶輸入用戶名稱后:鼠標(biāo)離開文本框后效果如下:

標(biāo)簽:崇左 晉城 撫州 銅川 西藏 伊春 深圳 威海

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ajax 服務(wù)器文本框自動(dòng)填值》,本文關(guān)鍵詞  ajax,服務(wù)器,文本,框,自動(dòng),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ajax 服務(wù)器文本框自動(dòng)填值》相關(guān)的同類信息!
  • 本頁收集關(guān)于ajax 服務(wù)器文本框自動(dòng)填值的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    潞西市| 金川县| 兴安县| 攀枝花市| 大荔县| 台南市| 宜昌市| 宁海县| 乐东| 惠东县| 崇义县| 昭苏县| 涪陵区| 抚远县| 台江县| 霍林郭勒市| 溧水县| 芷江| 桓台县| 左贡县| 博乐市| 罗城| 黔东| 鲜城| 绍兴县| 灵武市| 庆元县| 新巴尔虎右旗| 房山区| 广宗县| 辛集市| 伊金霍洛旗| 开鲁县| 泸定县| 五大连池市| 沂源县| 河津市| 乐昌市| 共和县| 防城港市| 车致|