I've got a nifty problem!
I've created an ASP.NET page with an updatepanel and a trigger on that updatepanel. The trigger updates the panel every 30 seconds.
The problem is that when the trigger updates the panel, IE8 takes the focus from any other program that I'm using.
Does anyone have a solution for this?
This happens in IE8; in Firefox I've got no problems with this.
This is the timer with updatepanel:
<asp:Timer ID="Timer1" runat="server" Interval="30000" ontick="Timer1_Tick">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
<asp:AsyncPostBackTrigger ControlID="ButtonSubmit" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
Loading....
</ProgressTemplate>
</asp:UpdateProgress>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder><br />
<div class="clear"></div>
<asp:Label ID="Label4" runat="server" Text="Grid not refreshed yet.">
</asp:Label><br />
<asp:Label ID="Label5" runat="server" Text="(Grid Will Referesh after Every 30 Sec)" Font-Bold="true"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
On the timer tick I only perform this action:
protected void Timer1_Tick(object sender, EventArgs e)
{
Label4.Text = "Grid Refreshed at: " + DateTime.Now.ToLongTimeString();
}
Thanks in advance.
I hope anyone knows why IE8 "steals" the focus.
Try the Live event, this should solve your problem. http://docs.jquery.com/Events/live
Related
I use updatepanel in my page like this.
but when I run my app when I click on button that's refresh all of my page.
I do'nt know what I can do to solve this error.
even I use treeview in other page that when I get this error the treeview icon dont show.
please help me.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="updPanl" runat="server" RenderMode="Block" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
try this
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="updPanl" ChildrenAsTriggers="true" runat="server" RenderMode="Block" UpdateMode="Conditional" >
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
protected void Button1_Click(object sender, EventArgs e)
{
updPanl.Update();
}
after three days I can find this problem today so I answer this question maybe this help to otherone.
I use routin in my app so webresource and scriptresouce could not load in asp page
I use this code for do not route this resource
routeCollection.Add(new Route("{resource}.axd/{*pathInfo}", new StopRoutingHandler()));
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>
I have a listbox that is being updated via a timer and working as expected inside an UpdatePanel.
However I cannot get the selectedindexchanged event to fire. I presume this is something to do with the partial postback. Does anybody know what I can do to make this work?
When I move it out of the UpdatePanel it works fine. However obviously I cannot do partial postbacks.
<asp:UpdatePanel ID="UpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="500"></asp:Timer>
<asp:ListBox ID="ListBox_JobPositions" OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged" runat="server" Height="750px" Width="300px" DataSourceID="sqlDataSource" DataTextField="Company" DataValueField="Pid"></asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
UPDATE:
Have now tried the below change, the timer event is still working but the selectedindexchanged event is not. I am getting lost with this.
<asp:UpdatePanel ID="UpdatePanel" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="500"></asp:Timer>
<asp:ListBox ID="ListBox_JobPositions" runat="server" Height="750px" Width="300px" DataSourceID="sqlDataSource" DataTextField="Company" DataValueField="Pid" OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged" AutoPostBack="True"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>
Here is the event that does not fire when the listbox is inside the UpdatePanel but does work when it is not.
protected void ListBox_JobPositions_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Write("test");
}
The reason you are not getting the event is that, your change event is not causing the PostBack. Your postback is caused by the timer.
The event asp.net receives is the timer event and not the ListBox event.
To resolve the issue, you should set AutoPostBack to true. This will cause the ListBox to do a PostBack as soon as the data changes and your event should fire.
<asp:ListBox ID="ListBox_JobPositions" AutoPostBack="True"
OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged"
runat="server" Height="750px" Width="300px"
DataSourceID="sqlDataSource"
DataTextField="Company"
DataValueField="Pid">
</asp:ListBox>
Since you have set the UpdateMode to Conditional, you should also set the ChildrenAsTriggers to true. This way way the List causes a PostBack, that too will be a partial update.
<asp:UpdatePanel ID="UpdatePanel" runat="server"
UpdateMode="Conditional"
ChildrenAsTriggers="True">
Works now, had to manually specify Async and Full Postback triggers. Thanks for your help.
<asp:UpdatePanel ID="UpdatePanel" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="500"></asp:Timer>
<asp:ListBox ID="ListBox_JobPositions" runat="server" Height="750px" Width="300px" DataSourceID="sqlDataSource" DataTextField="Company" DataValueField="Pid" OnSelectedIndexChanged="ListBox_JobPositions_SelectedIndexChanged" AutoPostBack="True"></asp:ListBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
<asp:PostBackTrigger ControlID="ListBox_JobPositions" />
</Triggers>
</asp:UpdatePanel>
I want to show the UpdateProgress on page A when a user clicks on the "Next" button to go to next page. The next page is Page B, which has heavy data loading.
When the button is clicked, it doesn't show the UpdateProgress.
What's missing from this code, and how can it be made to show?
<asp:UpdateProgress ID="UpdateProgress1" runat="Server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate >
Please wait ...
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnNext" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="btnCancel" runat="server" TabIndex="1" Text="Cancel"onclick="btnCancel_Click" />
<asp:Button ID="btnNext" runat="server" TabIndex="2" Text="Next" onclick="btnNext_Click" />
</ContentTemplate>
</asp:UpdatePanel>
Try setting DisplayAfter to a very small value to make the progress indicator appear immediately, e.g.:
<asp:UpdateProgress ID="UpdateProgress1" runat="Server" AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="1">
Couple of things to try:
1) Move the UpdateProgress control inside the UpdatePanel
2) Remove the AssociatedUpdatePanelID attribute from the UpdateProgress tag
I'm banking on Option 1 doing the trick.
EDIT
Here is a non-ProgressTemplate way, using client-side event handlers:
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args)
{
// some code to show image, e.g:
document.getElementById('somedivwhichasimage').className = 'show';
}
function EndRequestHandler(sender, args)
{
// some code to hide image, e.g:
document.getElementById('somedivwhichasimage').className = 'hidden';
}
</script>
Add this code on the code behind of this page.
protected void btnNext_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(3000);
}
Hope this helps!!
Edit:
Follow this link:
http://msdn.microsoft.com/en-us/library/bb386421.aspx
Adding the code from aspx page that I tried and is working,
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<asp:UpdateProgress ID="UpdateProgress1" runat="Server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate >
<asp:Label ID="lblwait" runat="server" Text="Please wait.."></asp:Label>
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:Button ID="btnCancel" runat="server" TabIndex="1" Text="Cancel" />
<asp:Button ID="Button1" runat="server" TabIndex="2" Text="Next" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
try putting UpdateProgress control inside UpdatePanel. and that should work for you.
hope that helps!
I have a page with some UpdatePanels, each one with its own button to update it. Since the update routines can take some time, I thought making them Asynchronous would help loading the page step by step.
But doing so, when I fire programatically the update routine of each panel, I get only the last UpdatePanel updated.
Here is an example of the code, with two UpdatePanels. There is the requirement that the update routine have to be fired on clientside pageLoad function.
Is it a bug or am I missing something in the code?
Thanks =)
<asp:UpdatePanel ID="Panel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="Text1" runat="server" />
<asp:Button ID="Button1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="Panel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="Text2" runat="server" />
<asp:Button ID="Button2" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
And the client-side code:
function pageLoad()
{
$('#Button1').click();
$('#Button2').click();
}
Here is why:
By default, when a page makes multiple
asynchronous postbacks at the same
time, the postback made most recently
takes precedence.
http://www.asp.net/ajax/documentation/live/tutorials/ExclusiveAsyncPostback.aspx
Here is a solution:
Handling Multiple Asynchronous Postbacks