asp.net UpdateProgress for Gridview that is triggered by a Button - asp.net

I want to show an UpdateProgress on the Page, when the Button is clicked and while the Gridiew is loading. However, I want to show the loading image next to the Button and not instead of the Gridview.
When the button is clicked, it doesn't show the UpdateProgress. What is missing from my code?
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="OKButton" runat="server" Text="OK" Width="48px" onclick="OKButton_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="OKButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdateProgress id="UpdateProgress1" runat="server" DisplayAfter="0" AssociatedUpdatePanelID="UpdatePanel">
<ProgressTemplate><img scr="../images/wait.gif" /></ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel runat="server" id="UpdatePanel2" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="OKButton" eventname="Click" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server".....>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Thanks for reply...I was trying to upload the image, however, I was unable to do so..
just to give an idea:
From Date _.................| Gridview
To Date __ ...................|
OK Button Image..........|
I know its not great. But I hope it gives an idea on how i'd like to place the button on the left side and GridView on the right side on the screen. The "Image" shows, where i'd like the image of UpdateProgress to be placed, while the GridvView is loading its content.

Related

Make any button on the page as a trigger for an asp.net UpdatePanel other than its sibling or child postback controls

Consider the following code fragment:
<div>
<asp:Button runat="server" ID="trickyUPTrigger" Text="Tricky Update" />
<div>
<asp:Button runat="server" ID="normalUPTrigger" OnClick="normalUPTrigger_Click" Text="Normal Update" />
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="normalUPTrigger" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" ID="changeableLabel" Text="Change me"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
Now make the button with ID of trickyUPTrigger as the trigger of the UpdatePanel. Or, devise a mechanism (probably... using javascript?) so that when this button is clicked UpdatePanel updates without full page postback.
If you want to update the UpdatePanel when clicking on trickyUPTrigger, you can add that button to the triggers list:
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="normalUPTrigger" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="trickyUPTrigger" EventName="Click" />
</Triggers>
<ContentTemplate>
...
</ContentTemplate>
</asp:UpdatePanel>
UPDATE
You asked some code examples showing cases with naming containers, a concept that comes into play for databound controls with item templates, like the GridView and the ListView, and for user controls. In the examples below, I use a ListView, where each item is a separate naming container.
If you wanted to trigger an update of your panel from a button in a ListView item template, the trigger would not be found at runtime, and an exception would occur:
<asp:ListView ID="lstView" runat="server">
<ItemTemplate>
<asp:Button ID="anotherTrigger" runat="server" Text="This trigger cannot be found!" OnClick="anotherTrigger_Click" />
</ItemTemplate>
</asp:ListView>
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="anotherTrigger" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
The reverse case (the UpdatePanel in the ListView item template, the trigger button outside of the ListView) does work, according to my tests, which seems to contradict the note that you mention in your comment:
<asp:ListView ID="lstView" runat="server">
<ItemTemplate>
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="anotherTrigger" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
</asp:ListView>
<asp:Button ID="anotherTrigger" runat="server" Text="This trigger works!" OnClick="anotherTrigger_Click" />
Finally, the case where the UpdatePanel and the trigger button are both in the ListView item template also works:
<asp:ListView ID="lstView" runat="server">
<ItemTemplate>
<asp:Button ID="anotherTrigger" runat="server" Text="This trigger works!" OnClick="anotherTrigger_Click" />
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="anotherTrigger" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
</asp:ListView>
You can notice that I set UpdateMode="Conditional" for the panel in this last example. With this setting, the panel is updated only by its own triggers. If the attribute is set to UpdateMode="Always", the panel is updated not only by his own triggers but also by the triggers of the other UpdatePanels in the page. The default value is UpdateMode="Always" (as in your code sample).

Why does a masterpage's UpdatePanel trigger event also trigger an UpdatePanel in a content page?

I have the following updatepanel in the masterpage:
<asp:UpdatePanel runat="server" id="pnlHeartBeat" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="HeartBeat" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Timer runat="server" id="HeartBeat" Interval="180000" OnTick="Heartbeat_OnTick"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
This runs fine no matter where I am in the site... right up to the point I navigate to a content page with another updatepanel, after which whenever the masterpage's updatepanel is triggered, so will the content page's updatepanel.
Here's a content page updatepanel:
<asp:UpdatePanel ID="ajaxColumnGroups" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cboxAllorNone" EventName="CheckedChanged" />
</Triggers>
<contenttemplate>
<dx:ASPxCheckBox ID="cboxAllorNone" runat="server" text="Select/Deselect All" OnCheckedChanged="cboxAllorNone_CheckChanged" autopostback="true"></dx:ASPxCheckBox>
<dx:ASPxPageControl runat="server" id="tabColumnGroups" ActiveTabIndex="0"></dx:ASPxPageControl>
</contenttemplate>
</asp:UpdatePanel>
How can I stop this behavior?
Thanks

How to avoid timer reset in asp.net/ajax

I am using updatepanel and timer to display an alert every 15 seconds. It is working fine when I am not clicking anything in the page. It displays alert every 15 seconds. I have a button outside of this updatepanel. Whenever I click this button, the timer resets and it doesn't display alert every 15 seconds. If I stops clicking the button, it starts to display the alert after 15 seconds. BAsically, timer resets the interval when ever I click teh button. I want to display the alert regardless clicking a button or not. Please help me.
in ASPX page
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"
ViewStateMode="Enabled">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:Timer ID="Timer1" runat="server" Interval="15000" OnTick="Timer1_Tick">
</asp:Timer>
In .CS page
public void Timer1_Tick(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, typeof(Page), "ToggleScript", "
alert('Hello')", true);
}
Reason looks lik your button do a post back and your timer in out side the update panel so it will reset.
if you can place your button in to another update panel this will work.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ViewStateMode="Enabled">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick">
</asp:Timer>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>

How to update the controls present in two different update panels using the click event of two different buttons

I am quite new to learning asp.net, so the question that I am asking may sound quite basic but I still need an answer as I am doing r&d with some of the toipcs.
I have 2 update panels in my page. Each contains a label. There are two buttons on my page, on the click event of the first button the label in the first update panel should get updated. On the click of the second button the label in the second update panel should get updated.
However when I click any of the two buttons both the labels get updated.
In the load event of the page the foll code is written
Label2.Text = DateTime.Now.ToString();
Label3.Text = DateTime.Now.ToString();
The code for both the update panel is as follows:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID= "Button1" EventName="click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="click" />
</Triggers>
</asp:UpdatePanel>
Remove the code from the page_load method and place it in the event of each of the buttons. So for button1 you put the code that updates label1 and for button2 you put the code that updates the label2.
You don't even need the triggers unless you're doing cross panel events. However, you do need to properly set up your script manager and update panels:
<asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePartialRendering="true"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"
UpdateMode="Conditional" OnLoad="Panel1_Load">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Button1"/>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server"
UpdateMode="Conditional" OnLoad="Panel2_Load">
<ContentTemplate>
<asp:Button ID="Button2" runat="server" Text="Button2"/>
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
Here you'd put your code in Panel1_Load(){} and Panel2_Load(){}.
Notice the settings: EnablePartialRendering="true"
and: UpdateMode="Conditional"
If you don't want the asp:Button controls on your panels, you'd have to put them somewhere that would block their normal full post-back behavior.

gridview that is updated frequently

I have a ASP.NET gridview that shows some entries from the database. The entries need to be updated very frequently (if a modification occurs on the database, it should be reflected in the asp.net website within at most 3seconds).
The solution I am thinking about is to put the gridview inside an update panel and refresh the page every 3 seconds. Is there a better alternative?
By using Timer in the update panel u can perform that update operation.For example ..
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000">
</asp:Timer>
</div>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="UpdatePanel1 not refreshed yet."></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="UpdatePanel2 not refreshed yet."></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
instead of label control u can use gridview.

Resources