Does anyone have a resource or provide a code sample on when not to display an UpdatePrgress Control when a certain button is clicked.
in your Markup:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel</legend>
<asp:Label ID="Label1" runat="server" Text="Initial page rendered."></asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
Processing...
</ProgressTemplate>
</asp:UpdateProgress>
in your code behind:
protected void Button1_Click(object sender, EventArgs e)
{
// Introducing delay for demonstration.
System.Threading.Thread.Sleep(3000);
Label1.Text = "Page refreshed at " +
DateTime.Now.ToString();
}
this should work, try it...
source: Introduction to the UpdateProgress Control
Related
I have a aspx is like shown below
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
<asp:UpdatePanel runat="server" ID="panel">
<ContentTemplate>
<asp:Button runat="server" id="bt" text="partial postback" OnClick="E" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" text="full postback" OnClick="J" />
<asp:UpdateProgress runat="server" ID="progress" DynamicLayout="true" AssociatedUpdatePanelID="panel">
<ProgressTemplate>
<div class="divWaiting">
<asp:Label ID="lbl" runat="server" Text="OK" />
<asp:Image ID="imgWait" runat="server" ImageAlign="Middle" ImageUrl="images/indicator.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
On Code Behind I have a function to update my label after making the thread sleep for 3 seconds
public void E(Object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
Label lbl = (Label)progress.FindControl("lbl");
if (lbl.ToString()!= null)
{
lbl.Text = "SomeThing";
}
update = true;
}
I have this code:
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="TickEvent"></asp:Timer>
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<img src="http://jimpunk.net/Loading/wp-content/uploads/loading18.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
Codebehind code:
protected void TickEvent(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
But when I run the page, the time doesn't update and the progresspanel doesn't show. Can any one help?
I solved it by recopying all the scripts files to Scripts folder
Here I try to update the Label value base on click event of Linkbutton which is inside the repeater control. Scenario is When I click on Linkbutton same time Modal popup open and the Label text also change.
Below is my code.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="ModalPopupUpdatePanel.aspx.cs"
Inherits="ModalPopupUpdatePanel" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!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>ModalPopups and UpdatePanels</title>
<link rel="stylesheet" href="StyleSheet.css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="scriptMgr1">
</asp:ScriptManager>
<div style="width: 300px; left: 100px">
<div >
<asp:Label ID="Label2" runat="server">Update Panel that contains a ModalPopup and its associated PopupPanel inside it</asp:Label>
<asp:UpdatePanel runat="server" ID="updatePanel2" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<br />
<asp:Repeater runat="server" ID="btnresr" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:LinkButton runat="server" ID="text" OnClick="Button5_Click" Text=' <%# DataBinder.Eval(Container.DataItem, "AgentName")%>' BackColor="Red"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
<asp:Button runat="server" ID="button2" Text="Launch Modal Popup2" style="display:none"/>
<ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupExtender2" TargetControlID="button2"
PopupControlID="modalPanel2" OkControlID="okBtn2" CancelControlID="cancelBtn2"
BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PTBWConnectionString %>"
SelectCommand="SELECT [AgentName], [AgentID] FROM [AgentMaster]">
</asp:SqlDataSource>
<asp:Panel runat="server" ID="modalPanel2" BackColor="AliceBlue" Style="display: none">
<asp:UpdatePanel runat="server" ID="updatePanel4" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Label runat="server" ID="label5" ></asp:Label>
<asp:Button runat="server" ID="postbackBtn" Text="Click to Cause postback" OnClick="postbackBtn_Click" /><br />
<asp:Button runat="server" ID="cancelBtn2" Text="OK" />
<asp:LinkButton runat="server" ID="okBtn2" Text="Cancel" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</form>
</body>
</html>
and Code behind
using System;
using System.Web.UI.WebControls;
public partial class ModalPopupUpdatePanel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void updateLabel_Click(object sender, EventArgs e)
{
}
protected void postbackBtn_Click(object sender, EventArgs e)
{
label5.Text = "After Postback";
}
protected void Button5_Click(object sender, EventArgs e)
{
LinkButton l = (LinkButton)sender;
label5.Text = "This is before postback,saroop";
modalPopupExtender2.Show();
}
}
I am block here please help me..Is there any Jquery way then also please here me
That is because the lable5 is not avaiable like that, it is nested inside the RepeaterItem.
Can you try this.
LinkButton l = (LinkButton)sender;
RepeaterItem rpt = (RepeaterItem)l.Parent();
Label label5 = (Label)rpt.FindControl("label5");
label5.Text = "This is before postback,saroop";
modalPopupExtender2.Show();
I have an UpdatePanel within it a textbox with a background color of yellow and a trigger for text-changed for the textbox and everything works fine except that the background color reverts to white when I write some text in the text box and then focus somewhere else.
What is causing this? Thanks.
Using asp.net 4.0
Here is the asp.net markup:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<span>
<asp:TextBox ID="sticky" runat="server" AutoPostBack="true"
Text='<%# Bind("sticky") %>' TextMode="MultiLine"
OnTextChanged="cSticky" />
</span>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="sticky" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
Here is the css:
#StickyDiv textarea
{
height:170px;
width:185px;
resize:none;
margin-top:1px;
border:none;
font-family:Comic Sans MS;
font-size:1.2em;
padding:3px;
line-height:1.1em;
}
And here is the jQuery:
$(function () {
$("#StickyDiv textarea:even").css("background-color","#ffff95");
$("#StickyDiv textarea:odd").css("background-color", "#fe8ab9");
});
Your problem is that when you do a update in the ajax panel your jquery is not called. If the text is changed you update the box to yellow and not call the javascript because it is rendered outside of your panel. To fix this you can register the script in you codebehide like:
ScriptManager.RegisterClientScriptBlock(Page,typeof(string),"JavaScriptCall",script.ToString(), false);
I did in the folowing example
in ASPX file
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" BackColor="Yellow" AutoPostBack="true" OnTextChanged="textChanged"></asp:TextBox>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
In Codebehind File
protected void textChanged(object sender, EventArgs e)
{
TextBox1.BackColor = System.Drawing.Color.Yellow;
Label1.Text = TextBox1.Text;
}
I Have a TextBox outside the UpdatePanel and a Button inside the Updatepanel When i click on the Button it show value in TextBox.
I Have Write Following Code.
<%# Register TagPrefix="AjaxToolKit" Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit" %>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="true" />
<asp:TextBox ID="TextBox5" runat="server" />
<asp:UpdatePanel runat="server" ID="Up1">
<ContentTemplate>
<asp:Button ID="btn" runat="server" onclick="btn_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
----------Code Behind---------
protected void btn_Click(object sender, EventArgs e)
{
TextBox5.Text = "20000";
}
Your textbox value can't be updated untill you put it in an update panel.
<ContentTemplate>
<asp:TextBox ID="TextBox5" runat="server" />
<asp:Button ID="btn" runat="server" onclick="btn_Click" />
</ContentTemplate>
OR, it would be better if you register a trigger of the button and pull your button out from your update, like...
<asp:UpdatePanel runat="server" ID="upnl" UpdateMode="Conditional" >
<ContentTemplate>
<asp:TextBox ID="TextBox5" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btn" EventName="Click" />
</Triggers>
</asp:UpdatePanel>