Ajax
Common AJAX applications, combined with JavaScript's dynamic manipulation of HTML elements, combine to make a graceful effect.
Or use Ajax.NET, set the same as the previous article, no longer tired.
The code is as follows:
163phototest.aspx.cs
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 _163phototest:system.web.ui.page
{
protected void Page_Load (object sender, EventArgs e)
{
Description. Text = GetDescription ();
AjaxPro.Utility.RegisterTypeForAjax (typeof (_163phototest));
}
Take the description in the database
Protected string GetDescription ()
{
Try
{
String Strcomm = "Select Photo_description from Tab_photo where photo_id=1";
SqlConnection myconn = new SqlConnection ("User id=sa;password=123;database =test;data source=z;");
MyConn.Open ();
SqlCommand Mycomm = new SqlCommand (Strcomm, myconn);
SqlDataReader myreader = Mycomm.executereader ();
Myreader.read ();
Return myreader.getstring (0);
}
Catch
{
Return "";
}
}
[Ajaxpro.ajaxmethod]
Save description in the database www.knowsky.com
public bool Updatedesc (string description)
{
Try
{
String strcomm = "Update Tab_photo set photo_description= '" + description + "' Where photo_id=1";
SqlConnection myconn = new SqlConnection ("User id=sa;password=123;database =test;data source=z;");
MyConn.Open ();
SqlCommand Mycomm = new SqlCommand (Strcomm, myconn);
Mycomm.executenonquery ();
return true;
}
Catch
{
return false;
}
}
}
163phototest.aspx
<%@ Page language= "C #" autoeventwireup= "true" codefile= "163phototest.aspx.cs" inherits= "_163phototest"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Untitled Page </title>
<script language= "javascript" type= "Text/javascript" >
function display ()
{
document.getElementById (' Descfield '). style.display= ' block ';
document.getElementById (' Descfield '). Value = document.getElementById (' description '). innertext;
document.getElementById (' description '). style.display= ' None ';
document.getElementById (' Save '). style.display= ' block ';
}
var s;
function Updatedesc ()
{
s= document.getElementById ("Descfield"). Value;
document.getElementById ("Descfield"). Value= "Being saved";
_163phototest.updatedesc (S,updatedesc_callback);
}
function Updatedesc_callback (res)
{
if (res)
{
document.getElementById (' description '). style.display= ' block ';
document.getElementById ("description"). innertext =s;
document.getElementById (' Descfield '). style.display= ' None ';
document.getElementById (' Save '). style.display= ' None ';
}
}
</script>
<body >
<form id= "Form1" runat= "Server" >
<div id= "Div1" onmousemove= "this.style.backgroundcolor= ' #C0C0FF"; ">
<asp:label id= "description" runat= "Server" text= "Label" ></asp:Label>
</div>
<input type= "text" id = "Descfield"/>
<input type= "button" id= "Update" value= "Modify description"/>
<input type= "button" id= "Save" value= "Saving changes"/>
<br/>
</form>
</body>
Source: Coder At the doorsill--wind to listen to the BLOG