refreshing entire page from within an updatepanel - c#

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" />

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!

ASP.NET dropdownlist selectedIndexChanged not getting triggered

I am trying to create a form as part of a website. In the form the user is shown a dropdownlist with serveral options. If the user chooses the "Other" option, then they should be presented with a text box to fill the description of the "other" choice.
My idea was to hide the div that contains the text box and enable it when the user changes the dropdown list choice to "other".
I am having an issue where in asp.net the dropdownlist "selectedindexchanged" event is not being triggered. Below is the HTML code and the cs code.
<%# Page Title="" Language="C#" MasterPageFile="~/master/Site1.Master" AutoEventWireup="true" CodeBehind="form.aspx.cs" Inherits="Project.forms.form" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="menu" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Banner" runat="server">
<img src="../../image.jpg" class="img-responsive" alt="Responsive image" />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<h2 class="branding_orange">Form</h2>
<div class="alert alert-danger" name="warningDiv" style="margin-top:10px" id="warningDiv" role="alert" runat="server">
<p name="warningMsg" id="warningMsg" runat="server"></p>
</div>
<form id="compliantForm" role="form" class="form" runat="server" data-toggle="validator" onsubmit="return validation();">
<div class="row">
.
.
.
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="form-group">
<label for="person-submitting-select">Is the person submitting this complaint an: <b style="color:red">*</b></label>
<asp:DropDownList ID="cboPersonSubmitting" runat="server" AutoPostBack = "True" OnSelectedIndexChanged = "OnSelectedIndexChanged">
<asp:ListItem Text="select" Value="0" />
<asp:ListItem Text="Employee" Value="1" />
<asp:ListItem Text="Customer" Value="2" />
<asp:ListItem Text="Other" Value="3" />
</asp:DropDownList>
</div>
</div>
.
.
.
.
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
</asp:Content>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Project.forms
{
public partial class form : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
cboPersonSubmitting.AutoPostBack = true;
warningDiv.Visible = false;
warningMsg.InnerHtml = "";
}
.
.
.
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
if (cboPersonSubmitting.SelectedIndex == 3)
{
whoSubmittingDiv.Visible = true;
}
else
{
whoSubmittingDiv.Visible = false;
}
}
}
}
Based on my test, you can try the following code to show textbox when you choose Other in the dropdownlist.
Html:
<form id="form1" runat="server">
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="form-group">
<label for="person-submitting-select">Is the person submitting this complaint an: <b style="color:red">*</b></label>
<asp:DropDownList ID="cboPersonSubmitting" runat="server" AutoPostBack = "True" OnSelectedIndexChanged="cboPersonSubmitting_SelectedIndexChanged">
<asp:ListItem Text="select" Value="0" />
<asp:ListItem Text="Employee" Value="1" />
<asp:ListItem Text="Customer" Value="2" />
<asp:ListItem Text="Other" Value="3" />
</asp:DropDownList>
<div class="Submitdiv" id="thediv" runat="server" visible="false">
<asp:TextBox ID="txtInput" runat="server" ></asp:TextBox>
</div>
</div>
</div>
</form>
C# code:
protected void cboPersonSubmitting_SelectedIndexChanged(object sender, EventArgs e)
{
if (cboPersonSubmitting.SelectedIndex == 3)
{
thediv.Visible = true;
}
else
{
thediv.Visible = false;
}
}
Result:

LinkButton C# OnClick event not firing within Formview ItemTemplate

I am having an issue with my "save" linkbutton firing and am at a loss. I have included the code for the form and code-behind. I have added some testing to see if the event is firing and it doesn't appear to be so. Any help is appreciated. I am a novice coder so excuse me if there are obvious issues or a better way to proceed. Ultimate goal is to update the entry in the database for the given screen info and then redisplay to updated info.
Again thank you in advance.
UPDATE: I have included the FULL-ish CODE: (removed the sensitive info)
CODEBEHIND:
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class matter : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
...
}
protected void fvdoc_ItemCommand(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
throw new Exception("Clicked");
}
throw new Exception("i've been Clicked");
}
}
PAGE:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="matter.aspx.cs" Inherits="matter" %>
<!DOCTYPE html>
<html>
<head>
<title>Wasatch Client Matter Index</title>
<link rel="shortcut icon" href="~/favicon.ico" type="image/x-icon" />
<meta name="viewport" charset="utf-8" content="width=device-width, initial-scale=1, user-scalable=no"/>
<!-- Latest compiled and minified CSS -->
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Ubuntu+Condensed' type='text/css' />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous" />
<link rel="stylesheet" href="Content/themes/Site.css" />
<!-- Latest compiled JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"/>
</head>
<body>
<div class="navbar">
<div class="row">
<h1 class="col-lg-8 col-lg-offset-2 text-center " style="align-content:center;">Matter Index </h1>
</div>
</div>
<div class="container-fluid">
<form id="form1" runat="server">
<div class="row">
<div class="col-lg-10 col-lg-offset-1 form-group">
<asp:FormView ID="fvdoc" runat="server" DataSourceID="gvdb" OnItemCommand="fvdoc_ItemCommand">
<ItemTemplate>
<h2 class="col-md-12"><asp:Label ID="tbname" runat="server" Text=<%# Bind("docid") %> /> - <asp:Label ID="lbID" runat="server" Text=<%# Bind("sName") %> /></h2>
<div class="left col-md-10">
<legend>Matter Info:</legend>
<div class="form-group"><asp:Label runat="server" Text="Matter" AssociatedControlID="dcname"/>
<asp:TextBox ID="dcname" runat="server" CssClass="form-control" Text=<%# DataBinder.Eval(Container.DataItem,"sDocname") %> Enabled="true"/></div>
</div>
<div class="left col-md-10">
<hr />
<div class="form-group"><asp:Label runat="server" Text="Notes/Comments" AssociatedControlID="dcnotes" />
<asp:TextBox ID="dcnotes" runat="server" Rows="3" TextMode="MultiLine" Text=<%# Bind("sdocdesc") %> Enabled="true"/></div>
</div>
<div class="left col-md-6 col-md-offset-5 txsmall">
<asp:Label runat="server" Text="Filed: " Font-Bold="true" /><asp:Label ID="lblfiledate" runat="server" Text=<%# Bind("dtFiledate") %> CssClass="txsmall" Font-Italic="true" />
<asp:Label runat="server" Text="Modified: " Font-Bold="true" /><asp:Label ID="lblmodify" runat="server" Text=<%# Bind("dtLastModified") + " - " + Bind("susermodified") %> CssClass="txsmall" Font-Italic="true"/>
<asp:Label runat="server" CssClass="txsmall" id="lbltest"/>
</div>
<div class="clear-fix col-md-12">
<div class="form-group">
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" CssClass="clear-fix btn btn-primary" />
<asp:LinkButton runat="server" Text="Move" ID="MoveButton" CssClass="clear-fix btn btn-primary" CausesValidation="False" href="m.aspx" />
<asp:LinkButton runat="server" Text="Home" ID="HomeButton" CssClass="clear-fix btn btn-primary" CausesValidation="False" href="default.aspx"/>
</div>
</div>
</ItemTemplate>
</asp:FormView>
</div>
</div>
<hr class="col-lg-10 col-lg-offset-1" />
</form>
</div>
...
</body>
</html>
Your link button is present inside a formview item template as can be seen below and thus you will not get the individual control event (onclick event of linkbutton). Rather you need to handle the FormView.ItemCommand and do your processing like
<asp:FormView ID="fvdoc" runat="server"
DataSourceID="gvdb" onitemcommand="itemCommandClick">
<ItemTemplate>
.......
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" .........
In code behind handle this like
void itemCommandClick(Object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
LinkButton button = e.CommandSource as LinkButton;
//Do rest of the processing
}
}
Your FormView is missing the EditItemTemplate, like so:
<asp:FormView ID="fvdoc" runat="server" DataSourceID="gvdb" OnItemCommand="fvdoc_ItemCommand">
<ItemTemplate>
<!--... Use readonly controls like Label etc...-->
<asp:LinkButton runat="server" Text="Save" ID="EditButton" CommandName="Edit" CssClass="clear-fix btn btn-primary" />
</ItemTemplate>
<EditItemTemplate>
<!--... Use editable controls like TextBox etc...-->
<asp:LinkButton runat="server" Text="Save" ID="SaveButton" CommandName="Update" CssClass="clear-fix btn btn-primary" />
</EditItemTemplate>
</asp:FormView>
For the click on the Edit Button, change to Edit mode, then Handle the Save button to save the new values.
See the MSDN docs for more information.

Uploading images with a progress bar in asp.net 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

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.

Categories

Resources