Uploading images with a progress bar in asp.net c# - c#

I am writting a program (web site) which uploads images on the server,displays them and saves them in a folder. I want to add a progress bar which will be connected to the image's file size while it is being filled.Here is my Default.aspx file
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<br />
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<output id="images"></output>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvPhotos" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField ="Text" HeaderText="filename" />
<asp:ImageField DataImageUrlField="Value" ControlStyle-Height="250" ControlStyle-Width="250" HeaderText="Photo" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
Loading....<br />
<br />
</ProgressTemplate>
</asp:UpdateProgress>
</div>
<p>
<asp:Label ID="lblSuccess" runat="server"></asp:Label>
</p>
</form>
</body>
</html>
This is Default.aspx.cs
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.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
List<ListItem> sia = new List<ListItem>();
if(FileUpload1.HasFiles)
{
foreach(var file in FileUpload1.PostedFiles)
{ string[] fileName = Directory.GetFiles(Server.MapPath("~/Images/"));
file.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"), file.FileName));
Response.Write(file.FileName + " - " + file.ContentLength + " Bytes. <br />");
sia.Add(new ListItem(file.FileName, "~/Images/" + file.FileName));
}
lblSuccess.Text = string.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count);
}
gvPhotos.DataSource = sia;
gvPhotos.DataBind();
}
}
Please help me in inserting a jquery bar in my Default.aspx. Thank you in advance

Related

ASP.NET AsyncPostBackTrigger Not Firing in UpdatePanel

When using UpdatePanel, the AsyncPostBackTrigger is not firing on the server side. Originally, I thought it was because I'm using a MasterPage and the ScriptManager was not loading correctly so I created a test template but it still won't fire. However, the UpdateProgress does appear. This button is being used to export a report from Crystal Reports. Below is my following code:
Client Side:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApplication1.Test" %>
<%# Register Assembly="CrystalDecisions.Web, Version=13.0.4000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script src="cr/crystalreportviewers13/js/crviewer/crv.js" type="text/javascript">
</script>
<script>
</script>
<form id="form1" runat="server">
<div>
<p>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
</p>
</div>
<div>
<asp:Label ID="test" runat="server"></asp:Label>
<asp:RadioButtonList ID="rblFormat" runat="server" RepeatDirection="Horizontal" Width="130px" >
<asp:ListItem Text=" Excel" Value="Excel" />
<asp:ListItem Text=" PDF" Value="PDF" />
</asp:RadioButtonList>
<asp:ScriptManager runat="server" ></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Button ID="btnExport" CssClass="btn btn-primary" Text="Export" runat="server" CausesValidation="false"
OnClick="btnExport_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnExport" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div>
<font color="red"> Generating Download</font>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
</form>
</body>
</html>
Server-Side
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using static System.Net.Mime.MediaTypeNames;
namespace WebApplication1
{
public partial class Test : System.Web.UI.Page
{
ReportDocument crystalReport;
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.CrystalReportViewer1);
scriptManager.RegisterPostBackControl(this.btnExport);
crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("cr/missing_dob.rpt"));
crystalReport.SetDatabaseLogon("test", "test");
CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
CrystalReportViewer1.ReportSource = crystalReport;
}
protected void btnExport_Click(object sender, EventArgs e)
{
ExportFormatType formatType = ExportFormatType.NoFormat;
switch (rblFormat.SelectedItem.Value)
{
case "PDF":
formatType = ExportFormatType.PortableDocFormat;
break;
case "Excel":
formatType = ExportFormatType.Excel;
break;
}
crystalReport.ExportToHttpResponse(formatType, Response, true, "Report");
}
}
}
PostBackTrigger works but the UpdateProcess does not appear. I can't seem to get both working. I appreciate any help!

put reset button in default for code in user control page

this code in user control.ascx page
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Dates.ascx.cs" Inherits="WebApplication3.Dates" %>
<b>Arivval Date: </b><br /> <br />
<asp:Calendar runat="server" ID="Arivval" ></asp:Calendar><br />
<b>Depart Date: </b> <br /> <br />
<asp:Calendar runat="server" ID="Depart" ></asp:Calendar>
and this code in web form page (default.ascx )
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="HotelReservation.aspx.cs" Inherits="WebApplication3.HotelReservation" %>
<%# Register TagPrefix="dt" TagName="Date" Src="~/Dates.ascx" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
</head>
<body>
<asp:Panel runat="server" ID="ph">
<form id="form1" runat="server">
<asp:ImageButton ImageUrl="~/HotelImageButton.jpg" ID="HOTEL" runat="server" PostBackUrl="~/HotelReservation.aspx" />
<asp:ImageButton ImageUrl="~/CarImageButton.jpg" ID="CAR" runat="server" PostBackUrl="~/CarReservation.aspx" />
<h1 > Hotel Search </h1>
<dt:Date id="d" runat="server" /> <br />
<b>Nights:</b> <asp:TextBox id="num" runat="server" TextMode="Number" />
<br /> <br/>
<b> Room Type:</b> <br /> <br />
<asp:RadioButton id="Superior" runat="server" text="Superior" GroupName="RoomType" /> <br />
<asp:RadioButton id="Twin" runat="server" text="Twin" GroupName="RoomType" /> <br />
<asp:RadioButton id="Triple" runat="server" text="Triple" GroupName="RoomType" /> <br />
<asp:RadioButton id="DeLuxe" runat="server" text="DeLuxe" GroupName="RoomType" /> <br />
<asp:RadioButton id="Studio" runat="server" text="Studio" GroupName="RoomType" /> <br />
<br /> <br />
<asp:Button ID="search" Text="Search" runat="server" />
<asp:Button ID="Reset" Text="Reset" runat="server" style="margin-left: 51px" Width="61px" OnClick="Clear" />
</form>
</asp:Panel>
</body>
</html>
in default.ascx.cs page i want to put reset button for calendar in the user control how to do it
protected void Clear(object sender, EventArgs e)
{
num.Text = "";
Boolean f = false;
Superior.Checked = f;
Twin.Checked = f;
Triple.Checked = f;
DeLuxe.Checked = f;
Studio.Checked = f;
}
I want to put in default.ascx.cs in clear event code to make the 2 calendars in the control page unselected
Create public properties for selected dates in your user control and use them in the host page. Something like this.
<%# Control Language="C#" ClassName="Dates" %>
<script runat="server">
public DateTime ArivvalDate
{
get { return Arivval.SelectedDate; }
set { Arivval.SelectedDate = value; }
}
public DateTime DepartureDate
{
get { return Depart.SelectedDate; }
set { Depart.SelectedDate = value; }
}
</script>
<b>Arivval Date: </b><br /> <br />
<asp:Calendar runat="server" ID="Arivval" ></asp:Calendar><br />
<b>Depart Date: </b> <br /> <br />
<asp:Calendar runat="server" ID="Depart" ></asp:Calendar>
Page:
<!DOCTYPE html>
<%# Page Language="C#" %>
<%# Register Src="~/misc/Dates.ascx" TagPrefix="dt" TagName="Date" %>
<script runat="server">
protected void Clear(object sender, EventArgs e)
{
lstRoomType.SelectedIndex = -1;
d.ArivvalDate = DateTime.MinValue;
d.DepartureDate = DateTime.MinValue;
}
protected void search_Click(object sender, EventArgs e)
{
test.Text = string.Format("Arrival: {0:M/d/yy}, Departure: {1:M/d/yy}, Room Type: {2}", d.ArivvalDate, d.DepartureDate, lstRoomType.SelectedValue);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Reservation Form</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Hotel Search </h1>
<dt:Date ID="d" runat="server" />
<br />
<b>Nights:</b>
<asp:TextBox ID="num" runat="server" TextMode="Number" />
<br />
<br />
<b>Room Type:</b>
<br />
<br />
<%--use list instead of a set of individual RB --%>
<asp:RadioButtonList runat="server" ID="lstRoomType">
<asp:ListItem Text="Superior" Value="Superior" />
<asp:ListItem Text="Twin" Value="Twin" />
<asp:ListItem Text="Triple" Value="Triple" />
<asp:ListItem Text="Deluxe" Value="Deluxe" />
<asp:ListItem Text="Studio" Value="Studio" />
</asp:RadioButtonList>
<br />
<br />
<asp:Button ID="search" Text="Search" runat="server" OnClick="search_Click" />
<asp:Button ID="Reset" Text="Reset" runat="server" Style="margin-left: 51px" Width="61px" OnClick="Clear" />
<br />
<asp:Literal ID="test" runat="server" />
</div>
</form>
</body>
</html>

Session State C# Declaration Passing textbox.Text

Ok I have a fairly simple issue I want to define some session state variables
So far in my code behind in C# for an aspx page I have the following type of declaration working fine in my index.aspx.cs file.
Session[Constants.firstName] = "Jordan";
or
Session[Constants.firstName] = 123;
I want to grab the Text from the index.aspx Textboxes though instead like so.
Session[Constants.firstName] = txtb_FName.Text;
The problem is that changing this to the variable txtb_FName.Text does not work and when I debug it shows the local variable is being filled with "" not the input from my Textbox.
The whole CODE trail looks like this;
index.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="ProjectPhase02.index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Project Phase 02</title>
<link id="Link1" href="main.css" rel="stylesheet" runat="server" />
</head>
<body>
<form id="form1" runat="server" method="get" action="accountCreationConfirmation.aspx">
<div>
<asp:Label CssClass="accountFormLable" runat="server" Text="First Name: "></asp:Label>
<asp:TextBox ID="txtb_FName" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Last Name: "></asp:Label>
<asp:TextBox ID="txtb_LName" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="User Name: "></asp:Label>
<asp:TextBox ID="txtb_UName" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Password: "></asp:Label>
<asp:TextBox ID="txtb_Password" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Address: "></asp:Label>
<asp:TextBox ID="txtb_Address" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Email: "></asp:Label>
<asp:TextBox ID="txtb_Email" runat="server"></asp:TextBox>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Phone: "></asp:Label>
<asp:TextBox ID="txtb_Phone" runat="server"></asp:TextBox>
<br />
<asp:Button ID="submitButton" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>
index.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ProjectPhase02
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session[Constants.firstName] = txtb_FName.Text;
Session[Constants.lastName] = txtb_LName.Text;
Session[Constants.userName] = txtb_UName.Text;
Session[Constants.password] = txtb_Password.Text;
Session[Constants.address] = txtb_Address.Text;
Session[Constants.email] = txtb_Email.Text;
Session[Constants.phoneNumber] = txtb_Phone;
}
}
}
Constants.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ProjectPhase02
{
public static class Constants
{
public static string firstName = "thatFName";
public static string lastName = "thatLName";
public static string userName = "thatUName";
public static string password = "thatPass";
public static string address = "thatAddress";
public static string email = "thatEmail";
public static string phoneNumber = "thatPNumber";
}
}
accountCreationConfirmation.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ProjectPhase02
{
public partial class accountCreationConfirmation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string fN = (string) Session[Constants.firstName];
string lN = (string) Session[Constants.lastName];
string uN = (string) Session[Constants.userName];
string pW = (string) Session[Constants.password];
string ad = (string) Session[Constants.address];
string em = (string) Session[Constants.email];
string pN = (string) Session[Constants.phoneNumber];
lbl_FName.Text = fN;
lbl_LName.Text = lN;
lbl_UName.Text = uN;
lbl_Password.Text = pW;
lbl_Address.Text = ad;
lbl_Email.Text = em;
lbl_Phone.Text = pN;
}
}
}
accountCreationConfirmation.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="accountCreationConfirmation.aspx.cs" Inherits="ProjectPhase02.accountCreationConfirmation" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Project Phase 02</title>
<link id="Link1" href="main.css" rel="stylesheet" runat="server" />
</head>
<body>
<form id="form1" runat="server" >
<div>
<asp:Label CssClass="accountFormLable" runat="server" Text="First Name: "></asp:Label>
<asp:Label ID="lbl_FName" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Last Name: "></asp:Label>
<asp:Label ID="lbl_LName" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="User Name: "></asp:Label>
<asp:Label ID="lbl_UName" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Password: "></asp:Label>
<asp:Label ID="lbl_Password" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Address: "></asp:Label>
<asp:Label ID="lbl_Address" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Email: "></asp:Label>
<asp:Label ID="lbl_Email" runat="server"></asp:Label>
<br />
<asp:Label CssClass="accountFormLable" runat="server" Text="Phone: "></asp:Label>
<asp:Label ID="lbl_Phone" runat="server"></asp:Label>
<br />
</div>
</form>
</body>
</html>
main.css
.accountFormLable {
width: 100px;
float: left;
display: block;
clear: left;
}

Update UI controls outside the updatepanel in asp.net

I'm trying to update controls outisde the update panel with the ref. of below link . but its not working. i want to know what i'm missing.in my application can't use these labels inside the update panel.
http://msdn.microsoft.com/en-us/library/bb301423(v=vs.110).aspx
HTML
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="Updatepaneltest._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(PageLoadingHandler);
function PageLoadingHandler(sender, args) {
var dataItems = args.get_dataItems();
if ($get('Label1') !== null)
$get('Label1').innerHTML = dataItems['Label1'];
if ($get('Label2') !== null)
$get('Label2').innerHTML = dataItems['Label2'];
}
</script>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
UpdatePanel content.
<asp:Button ID="Button1" Text="Submit" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<hr />
<asp:Label ID="Label1" Text="hiii" runat="server" /> <br />
<asp:Label ID="Label2" runat="server" />
</div>
</asp:Content>
code behind
protected void Page_Load(object sender, EventArgs e)
{
// ScriptManager ScriptManager1 = ScriptManager.GetCurrent(this.Page);
if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)
{
ScriptManager1.RegisterDataItem(Label1, DateTime.Now.ToString());
ScriptManager1.RegisterDataItem(Label2, DateTime.Now.Year.ToString());
}
}
Control updates inside of updatepanel,
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" Text="Submit" runat="server" />
<asp:Label ID="Label1" Text="hiii" runat="server" /> <br />
<asp:Label ID="Label2" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Control updates outside of updatepanel,
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditional>
<ContentTemplate>
<asp:Button ID="Button1" Text="Submit" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Label ID="Label1" Text="hiii" runat="server" /> <br />
<asp:Label ID="Label2" runat="server" />
Later, write below lines in client side.
var pageInstance = Sys.WebForms.PageRequestManager.getInstance();
pageInstance.add_pageLoaded(UpdateLabelHandler);
function UpdateLabelHandler(sender, args)
{
var ControldataItems = args.get_dataItems();
if ($get('Label1') !== null)
$get('Label1').innerHTML = ControldataItems ['Label1'];
if ($get('Label2') !== null)
$get('Label2').innerHTML = ControldataItems ['Label2'];
}
Code Behind:
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterDataItem(Label1, DateTime.Now.ToString());
ScriptManager1.RegisterDataItem(Label2, DateTime.Now.Year.ToString());
}
Hope this may help you.

refreshing entire page from within an updatepanel

Here's my situation. I have a web forms page, and it's getting annoying when the entire page scrolls to the top every time you click a control, so I'm trying to apply update panels to my page.
The submit button may or may not be click-able depending on whether or not the contents of individual update panels are in a proper state.
When the submit button is clicked, It can potentially affect any of the controls on the page.
I understand that I can do some of this with the <triggers> tag element of the update panel, but I don't want to have to put everything on the page into an update panel with it's own trigger, I'd rather that the submit button just reload the entire page.
For the sake of simplicity I've put together a sample project to represent my page. It has a "reset" button, to represent the "submit" button.
The Master page:
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form runat="server">
<asp:ScriptManager ID="ScriptManager" runat="server" EnablePartialRendering="true" />
<div class="page">
<div class="header">
<div class="title">
<h1>
My ASP.NET Application
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ Log In ]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
[ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
</LoggedInTemplate>
</asp:LoginView>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
<asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
</Items>
</asp:Menu>
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
</body>
</html>
The default page:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:Label runat=server Text="This lable represents things not in update panels" ID="label1"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat=server>
<ContentTemplate>
<table>
<tr>
<td><asp:Button ID="button1" runat="server" OnClick="Button1_click" Text="Button 1" /></td>
<td><asp:TextBox ID="textBox1" runat="server" Text="StartText" Enabled="false" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat=server>
<ContentTemplate>
<table>
<tr>
<td><asp:Button ID="button2" runat="server" OnClick="Button2_click" Text="Button 2" /></td>
<td><asp:TextBox ID="textBox2" runat="server" Text="StartText" Enabled="false" /></td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanelReset" runat=server>
<ContentTemplate>
<asp:Button ID="reset" runat="server" OnClick="Reset_click" Text="reset" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="button1" EventName="click" />
<asp:AsyncPostBackTrigger ControlID="button2" EventName="click" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>
The code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_click(object sender, EventArgs e)
{
textBox1.Enabled = !textBox1.Enabled;
reset.Enabled = !textBox1.Enabled && !textBox2.Enabled;
}
protected void Button2_click(object sender, EventArgs e)
{
textBox2.Enabled = !textBox2.Enabled;
reset.Enabled = !textBox1.Enabled && !textBox2.Enabled;
}
protected void Reset_click(object sender, EventArgs e)
{
textBox1.Text = "StartText";
textBox2.Text = "StartText";
label1.Text = "reset button clicked";
}
}
}
Just add a PostBackTrigger to the last UpdatePanel.
<asp:PostBackTrigger ControlID="reset" />

Categories

Resources