Ajax to achieve the changes in the style of NetEase albums

Source: Internet
Author: User
Tags return string
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



Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.