Asp.net updatePanel implements brushless newest application instances

Source: Internet
Author: User
Tags current time

Vs.net refreshing

The code is as follows: Copy code

<Asp: ScriptManager ID = "ScriptManager1" runat = "server">
</Asp: ScriptManager>
<H2>
Use The VS control updatePanel to achieve no refreshing
</H2>
<P>
<Asp: UpdatePanel ID = "UpdatePanel1" RenderMode = "Block" UpdateMode = "Conditional" runat = "server">
<ContentTemplate>
Click the button to obtain the current time from the server <asp: TextBox ID = "txtTime" runat = "server"> </asp: TextBox>
<Asp: Button ID = "btn1" runat = "server" Text = "Button" onclick = "btn1_Click"/>
</ContentTemplate>
<Triggers>
<% -- <Asp: PostBackTrigger ControlID = "btn1"/> -- %>
<Asp: AsyncPostBackTrigger ControlID = "btn1"/>
</Triggers>
</Asp: UpdatePanel>
</P>

Background code

 

The code is as follows: Copy code
Protected void btn1_Click (object sender, EventArgs e)
{
TxtTime. Text = DateTime. Now. ToString ();
}

Upload images without refreshing

 

The code is as follows: Copy code
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs" Inherits = "_ Default" %>
<! 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>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
<Asp: UpdatePanel ID = "UpdatePanel1" runat = "server" UpdateMode = "Conditional">
<ContentTemplate>
<Asp: ScriptManager ID = "ScriptManager1" runat = "server">
</Asp: ScriptManager>
<Asp: Button ID = "Button1" runat = "server" OnClick = "button#click" Text = "Button"/>
<Asp: FileUpload ID = "File1" runat = "server" Width = "200px"/>
</ContentTemplate>
<Triggers>
<Asp: PostBackTrigger ControlID = "Button1"/>
</Triggers>
</Asp: UpdatePanel>
<Asp: Image id = "image1" ImageUrl = "nopic.gif" Height = "115px" Width = "108px" runat = "server"/>
</Div>
</Form>
</Body>
</Html>

Background code

The code is as follows: Copy code


Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. IO;
Using System. Data. SqlClient;
Using System. Data;
Public partial class _ Default: baseClass
{
Protected void Page_Load (object sender, EventArgs e)
{
}
Protected void button#click (object sender, EventArgs e)
{
HttpPostedFile upFile = File1.PostedFile;
Int iFileLength = upFile. ContentLength;
Try
{
If (iFileLength = 0)
{
MessageBox ("select the file to upload! ");
}
Else
{
Byte [] FileByteArray = new Byte [iFileLength];
Stream StreamObject = upFile. InputStream;
StreamObject. Read (FileByteArray, 0, iFileLength );
SqlConnection conn = new SqlConnection ("server = ..; database = Test; uid = sa; pwd = 1234 ;");
ExecuteBySQLNonQuery ("delete from imageTable ");
SqlCommand cmd = new SqlCommand ("insert into [imageTable] values (@ image)", conn );
Cmd. Parameters. Add ("@ Image", SqlDbType. Binary, iFileLength). Value = FileByteArray;
Conn. Open ();
Cmd. ExecuteNonQuery ();
Conn. Close ();
MessageBox ("The photo has been uploaded successfully! ");
}
Image1.ImageUrl = "displayempphoto. ashx ";
}
Catch (Exception ex)
{
MessageBox (ex. Message );
}
}
}

Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.