Showing posts with label panel. Show all posts
Showing posts with label panel. Show all posts

Wednesday, March 28, 2012

Multiple PopupControlExtender - HOW?

Hi!

For example I have 10 textbox on my page. I created a panel with a calendar inside. I use 10 PopupControlExtender to bound the same panel to every textbox. (i dont want to create 10 diffrent Panels!)

And now i have a problem: How can i found out which PopupcontrolExtener and/or Textbox opend the calendar? I need this to set the value.

Any idea?

Thank you and sorry for bad english ;-)

Make it a user control. I've already done this and other than the issues that I've noted in some other posts about the popup behavior no longer working after postback, it works just fine. Below is the code I use to create the UserControl.

<%@. Control Language="C#" AutoEventWireup="true" CodeFile="DatePicker.ascx.cs" Inherits="User_Controls_DatePicker" %>
<asp:TextBox ID="tbDateSelected" runat="server" SkinID="DateTextBox"></asp:TextBox>
<asp:Panel ID="Panel1" runat="server" CssClass="popupControl">
<aspAjax:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<center>
<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#999999"
CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="Black" Width="160px" OnSelectionChanged="Calendar1_SelectionChanged">
<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
<SelectorStyle BackColor="#CCCCCC" />
<WeekendDayStyle BackColor="#FFFFCC" />
<OtherMonthDayStyle ForeColor="#808080" />
<NextPrevStyle VerticalAlign="Bottom" />
<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />
<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
</asp:Calendar>
<asp:ImageButton ID="imgCancel" runat="server" ImageUrl="../images/close.gif" OnClick="imgCancel_Click" />
</center>
</ContentTemplate>
</aspAjax:UpdatePanel>
</asp:Panel>
<ajaxToolkit:PopupControlExtender ID="pceDate" runat="server" PopupControlID="Panel1" TargetControlID="tbDateSelected" Position="Bottom" ></ajaxToolkit:PopupControlExtender>
<ajaxToolkit:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="Panel1" Radius="6" Opacity="1" TrackPosition="true" Width="5">
</ajaxToolkit:DropShadowExtender
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;

public partial class User_Controls_DatePicker : System.Web.UI.UserControl
{
private string _selectedDate;

public string SelectedDate
{
get { return tbDateSelected.Text; }
set { tbDateSelected.Text = value; }
}

public string Position
{
set { pceDate.Position = ( PopupControlPopupPosition ) Enum.Parse( typeof( PopupControlPopupPosition ), value ); }
}

protected void Page_Load( object sender, EventArgs e )
{
}

protected void Calendar1_SelectionChanged( object sender, EventArgs e )
{
pceDate.Commit( Calendar1.SelectedDate.ToShortDateString( ) );
}
protected void imgCancel_Click( object sender, ImageClickEventArgs e )
{
pceDate.Cancel( );
}
}

Hope this helps.

Nick


You can find out which PopupControlExtender called the calendar with the info accessible by calling this following function, in the event handler for the control you popped up:

 
AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page)
You can use that in, say, your calendar's OnSelectedDateChanged event handler to see where it needs to go.

You can use the .Commit() function to submit the information from the calendar to the correct control. Once again, this would go in the event handler for your calendar's OnSelectedDateChanged event handler.

AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page).Commit(Calendar1.SelectedDate.toString())
 
Thanks toTed Glaza for the assist. 

Hello!

Thanks for your reply!

@.ncipollina
Thats not the right solution. I dont want to deliver 10 rendered controls (With the same content!) to the client. Thats to much overhead!

@.Matt M
Hi! That sounds interessting. But I dont get the point.

Protected Sub Calender_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim currentPopupControlExtender as AjaxControlToolkit.PopupControlExtender = AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page)
currentPopupControlExtender.Commit(DirectCast(sender, Calendar).SelectedDate)
End Sub

Is this what you mean? I will try it tomorrow!


Undying:

Hello!

Thanks for your reply!

@.ncipollina
Thats not the right solution. I dont want to deliver 10 rendered controls (With the same content!) to the client. Thats to much overhead!

@.Matt M
Hi! That sounds interessting. But I dont get the point.

Protected Sub Calender_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim currentPopupControlExtender as AjaxControlToolkit.PopupControlExtender = AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page)
currentPopupControlExtender.Commit(DirectCast(sender, Calendar).SelectedDate)
End Sub

Is this what you mean? I will try it tomorrow!

Use

AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page).TargetControlID
to find the TargetControlID of the PopupControlExtender that caused the panel to pop up. In other words, what textbox is the target of the PopupControlExtender.
 
Is that what you are looking for? 

Matt you are the man!

Protected

Sub Calender_SelectionChanged(ByVal senderAsObject,ByVal eAs System.EventArgs)

AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(

Me).Commit(DirectCast(sender, Calendar).SelectedDate)EndSub

This work like a charme! I could use the Same "DatePickerPanel" on my page many times without duplicate code. Just add a Extender to the textbox and I'm done! Fine!

Thanks again for sharing this!


I am not sure that this actually works. I mean, the commit on the proxy works, but if I try to retrieve the value of TargetControlID from AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page).TargetControlID, it is null (which sense since what is returned from the getproxy method is an empty popupcontrolextender)

Is there any way to retrieve this information? I am trying to set the value of two textboxes, each based on the other and another arbittrary value...

i.e. - i would like my code to be soomething like:

AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page).Commit(calendar1.selecteddate.tostring())

select case AjaxControlToolkit.PopupControlExtender.GetProxyForCurrentPopup(Page).TargetControlID

case "text1"

text2.text=format(calendar1.selecteddate.addmonths(arbitrary value),"MM/dd/yyyy")

case "text2"

text1.text=format(calendar1.selecteddate.addmonths(-1*arbitrary value),"MM/dd/yyyy")

end select


Could you pleaseopen a work item to report and track this issue. Thank you!

Multiple Timers - Only on is ticking

Hi,

I have several UpdatePanels and a timer in each of them, as every panel has to be updated at different intervals. However, using the ASP.NET AJAX timer, only one is triggered and it seems to reset the other timers on the postback and thus the others never trigger. I was testing the Telerik Timer control and all of them were ticking properly, however it looks like they caused a memory leak in the WebDevServer as when using them, memory consumption always quickly shot up to over 1 GB.

Does anyone know of a fix or workaround how to get all timers ticking properly?

Thanks

Hi Daikoku,

as discussed inhttp://forums.asp.net/thread/1648410.aspx, the Ajax timers get reset on postback (even if they are in different update panels). I think they have only begun delving into the potential of these controls. I do not know that there is anything you can do about this behavior at this time.


Hi,

as soon as you put the Timers into the UpdatePanels, they will be reset after a partial postback.

Have you tried putting the Timers outside the UpdatePanels and referencing them as AsyncPostBack triggers?


When I place the timers outside the UpdatePanel, the whole page is reloaded on every tick

Hi,

if the timers are placed outside the UpdatePanel, you should add them as AsyncPostBack triggers for the UpdatePanel.


Thanks, that seems to work

Here is a solution I was able to use. Perhaps this will help someone visualize it. I have two timers counting off; 1 counts seconds, the other counts 60 seconds. each triggers an update panel which adds a number to a labels current integer value and re-enabled the calling trigger.

// codebehindprotected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) { Label1.Text ="0"; Label2.Text ="0"; } }protected void Timer1_Tick(object sender, EventArgs e) {int Time1 = Convert.ToInt16(Label1.Text); Time1 += 1; Label1.Text = Time1.ToString();if (Time1 >= 120)// stop the timer after two minutes ((Timer)sender).Enabled =false;else ((Timer)sender).Enabled =true; }protected void Timer2_Tick(object sender, EventArgs e) {int Time2 = Convert.ToInt16(Label2.Text); Time2 += 1; Label2.Text = Time2.ToString(); ((Timer)sender).Enabled =true; }
 <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> Seconds: <asp:Label ID="Label1" runat="server" Style=""></asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" /> </Triggers> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> Minutes: <asp:Label ID="Label2" runat="server" Style=""></asp:Label>  </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer2" /> </Triggers> </asp:UpdatePanel> </div> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"> </asp:Timer> <asp:Timer ID="Timer2" runat="server" OnTick="Timer2_Tick"> </asp:Timer>

Multiple Update Panels - Postback on Panel A cancels Postback on Panel B

Hi,

I have a page with multiple Update Panels. Each panel has a button as a trigger.

When the first button is clicked it causes the first panel to update (as you'd expect), however if while this panel is being updated, the second button is clicked to update the second panel, the first request is cancelled, and the first panel is never updated.

Is this the expected behavior? Are there any work arounds?

Many Thanks,
Ady

Yes, unfortunately it is by design. Only the last UpdatePanel requets will be considered and prior reuests discarded.

Hmm, thats a shame.

I wonder if there is a way to intercept the request, and effectively queue it until the first request completes.

Time to start playing.


This tutorial might help you get started:http://ajax.asp.net/docs/tutorials/ExclusiveAsyncPostback.aspx.

Multiple update panels

I had a query regarding multiple update panels.
I have a user control which contains one update panel.This user control contains a hidden textbox .
I am updating the updatepanel on basis of a timer control in javascripts which raises a postback.

I have placed two instances of this user control in another page say for eg. CIndexPage.aspx.
Now the Script manager is also placed in the same page ie CIndexPage.aspx.

Will the two updatepanels wrk independently.

Is the hidden variable shared between the instances of the update panel ?
Becoz the issue here is that even if i pass a value for the hidden textbox contained
in the first Update Panel, still the value gets stored for the hidden
variable in the second instance of the updatePanel.

Can we use Update Panels in a User Control and place multiple instances of the UserControls in a page.

Please if someone cld help me with this.

Thanks in advance.

Regards,
Shweta

hello.

well, the updatepanels will work independently. if you want to get independent refershes, you need to make sure that you've set the update mode of the pannel to conditional.

regarding the hidden field, it depends on how you've injected in the page...


Hi,

My Code is somewhat like this

User Control contains

_____________________________________________________________

<asp:UpdatePanel id=UpdatePanel1 runat=server>
<div id=DivCtrl runat=server >
<asp:HiddenField runat="server" ID="RequestID" Value="0" />
</UpdatePanel>


____________________________________________________________________
There is adiv control which contains multiple hyperlinks.That is done thru .cs file of the Master Control and is dynamically generated.
The hidden filed in placed inside the UpdatePanel and the RequestID is updated on the hyperlink click.

And 2 instances of this user control are placed in the Parent Page.
Also what happens is even though i am clicking on the first User Controls hyperlink (first updatepanel) still the Value is assigned to the second User Controls Hidden Field.

It always updates the last user control.

Why does work in this manner . Also to update the UpdatePanel i am using the timer control and _dopostback method.

Is there an issue with the timer control.Shld that be placed in the ParentPage.

regards,

Shweta


hello.

can you please build a small demo app with a simple user control + page and put it here?


yes sure
------------
User Control Code is as follows for .aspx is as follows
-------------
<script language =javascript>
var l_objtimer="";
l_objtimer =window.setInterval('UPdatePanel',1000);
function UPdatePanel()
{
var obj=get$('<%=RequestID.ClientID%>');
_dopostback("obj",'');
}

function CallDetails(nSerialNo)
{
var obj=get$('<%=RequestID.ClientID%>');
obj.value=nSerialNo;
_dopostback("obj",'');
}
</script>
<body>
<asp:UpdatePanel id=UpdatePanel1 runat=server>
<div id=DivCtrl runat=server >
<asp:HiddenField runat="server" ID="RequestID" Value="0" />
</UpdatePanel>
</body>

------------
end
-------------

------------
User Control Code is as follows for cs is as follows
-------------

In this i dynamically adding a hyperlink whose onclick events call CallDetails(nSerialNo) (in .aspx of user control).
And pass different value to the nSerialNo parameter on the click event.In the event i change the value of RequestID to the the nSerialNo.

------------
end
-------------

------------
Parent Page Code is as follows for .aspx is as follows
-------------
<%@. Register TagPrefix="csc" Namespace="CustomServerControls" %>
<body>
<asp:ScripManager runat=server id=ScriptMgr1 >
</asp:ScripManager >
<csc:CustomServerControls id=CustomServer1 runat=server >
</csc:CustomServerControls>

<csc:CustomServerControls id=CustomServer2 runat=server >
</csc:CustomServerControls>

</body>

------------
end
-------------

This way 2 instances of this user control are placed in the Parent Page.
Also what happens is even though i am clicking on the first User Controls hyperlink (first updatepanel) still the Value is assigned to the second User Controls Hidden Field.

Also if i am placing the usercontrol in a page and call the page thru <script tag by specifying the source it gives me a Syntax error.

Can i call the page in this way.


hello

well, now it's clear!. what you shoud do is change the js code. you should have something like this:

<script language =javascript>
var l_objtimer="";
l_objtimer =window.setInterval('UPdatePanel',1000);
function UPdatePanel(idCtl)
{
var obj=get$(idCtl);
_dopostback("obj",'');
}

function CallDetails(idCtl, nSerialNo)
{
var obj=get$(idCtl);
obj.value=nSerialNo;
_dopostback("obj",'');
}
</script>

where idCtl is the ID of the control (hidden field) you want to use. yep, you'll have to change your code so that it also passes the id of the field when you call the method.

in your code, what's happening is that when you're adding the second user control, it'll add the js methods again, overriding the previous definitions. this means that clicking on the 1st or 2nd user control will always call the latest definition, which points to the id of the last user control you've added to the page. if you perform the changes I've said, this won't happen any more.

Multiple Update Panel Animation Extenders on one page

Hi there!

I'm developing a web user control that contains an Update Panel and uses an Update Panel Animation Extender.
The animation is quite simple: while the panel is updating, it fades out the contents of the update panel and fades in the "please wait while processing..." message...then the animation reverses the process when the panel is Updated. The animation works quite nicely.

The problem I'm facing is when I have more than one of these web user controls on the page at a time (I'm using 8 of these on one page at a time).
If one web user control's update panel does an asynchronous postback, all of the animations are run!

Does anyone know how to get around this problem?

Thanks in advance,

-Frinny

Hi,

Would you please provide with any code of ypur usercontrol?

Or create a simple repro of this problem?

Thanks,


I forgot that I had posted this question.
I found the solution to my problem a while ago.

The problem I was describing is not actually a problem, it is how the UpdatePanelAnimationExtender works.

Anyways, to get around this problem I ended up using regular Animations instead of the UpdatePanelAnimationExtender.

Cheers!

Multiple Update Panels not exactly asynchronous

Hi,

I'm having trouble getting a page with 2 update panels to update themselves asynchronously. It appears, the update inside of one update panel is canceled as soon as the other update panel begins an update.

I want to be able to click a button inside of an update panel. Then, while that panel is updating, click on another button inside of another update panel without canceling the first update.

Not sure if this makes sense or if it's possible, but below is some code demonstrating the issue. When you try to click both buttons, the update of the first button is cancelled.

1<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>23<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>4<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">5<html xmlns="http://www.w3.org/1999/xhtml">6<head runat="server">7 <title>Untitled Page</title>8</head>9<body>10 <form id="form1" runat="server">11 <asp:ScriptManager ID="ScriptManager1" runat="server" />12 <div>13 <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">14 <ContentTemplate>15 <asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="UpdatePanel1">16 <ProgressTemplate>17 Updating UpdatePanel1...18 </ProgressTemplate>19 </asp:UpdateProgress>20 <asp:Label ID="lblUpdate1" runat="server"></asp:Label>21 <asp:Button ID="btnUpdate1" runat="server" OnClick="Button1_Click" Text="Update 1" />22 </ContentTemplate>23 <Triggers>24 <asp:AsyncPostBackTrigger ControlID="btnUpdate1" EventName="Click" />25 </Triggers>26 </asp:UpdatePanel>27 </div>28 <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">29 <ContentTemplate>30 <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel2">31 <ProgressTemplate>32 Updating UpdatePanel2...33 </ProgressTemplate>34 </asp:UpdateProgress>35 <asp:Label ID="lblUpdate2" runat="server"></asp:Label>36 <asp:Button ID="btnUpdate2" runat="server" OnClick="btnUpdate2_Click" Text="Update 2" />37 </ContentTemplate>38 <Triggers>39 <asp:AsyncPostBackTrigger ControlID="btnUpdate2" EventName="Click" />40 </Triggers>41 </asp:UpdatePanel>42 </form>43</body>44</html>45

1using System;2using System.Data;3using System.Configuration;4using System.Web;5using System.Web.Security;6using System.Web.UI;7using System.Web.UI.WebControls;8using System.Web.UI.WebControls.WebParts;9using System.Web.UI.HtmlControls;10using System.Threading;1112public partialclass _Default : System.Web.UI.Page13{14protected void Page_Load(object sender, EventArgs e)15 {1617 }1819protected void Button1_Click(object sender, EventArgs e)20 {21 Thread.Sleep(5000);22 lblUpdate1.Text = DateTime.Now.ToString();23 }24protected void btnUpdate2_Click(object sender, EventArgs e)25 {26 Thread.Sleep(5000);27 lblUpdate2.Text = DateTime.Now.ToString();28 }29}

Take a look at this post:http://forums.asp.net/t/1117212.aspx and this one:http://forums.asp.net/t/1108522.aspx

Basically, you can only have 1 asynchronous request at a time with UpdatePanels.

-Damien


See the link it will solve your problem

http://forums.asp.net/t/1108522.aspx


Awesome. That works great for buttons.

Any idea how to do the same thing for other events? Like a GridView Sorting or SelectedIndexChanged event?


Checkout this posthttp://geekswithblogs.net/rashid/archive/2007/08/08/Asp.net-Ajax-UpdatePanel-Simultaneous-Update--A-Remedy.aspx


KaziManzurRashid:

Checkout this posthttp://geekswithblogs.net/rashid/archive/2007/08/08/Asp.net-Ajax-UpdatePanel-Simultaneous-Update--A-Remedy.aspx

Thanks Kazi. That works, but for some reason it does not work if I use a MasterPage. I've tried putting the scriptmanager in the masterpage and in the webform using that master page and it doesn't work either way. Any ideas why?

EDIT: BTW, It appears the _doPostBack() method of the prm instance is not working for elements inside of a masterpage. Not sure what I'm doing wrong.


I was able to fix my MasterPage problem by making the changes suggested by the 2 comments in the blog.

I also made the following change to the endRequest() function in order to support GridView postbacks:

1function endRequest(sender, args)2 {3 //Check if we have a pending call4 if (_callQueue.length > 0)5 {6 //Get the first item from the call queue and setting it7 //as current executing item8 _executingElement = Array.dequeue(_callQueue);9 var _element = _executingElement[0];10 var _eventArg = _executingElement[1];1112 //Now Post the from which will also fire the initializeRequest13 if(_element.name != null)14 _prm._doPostBack(_element.name, _eventArg);15 else16 _prm._doPostBack(_element.id.replace(/_/g,"$"), _eventArg);17 }18 }

So basically if the executingElement does not have a name set, I create it by replacing the '_' characters in the id with '$' characters (not sure if this is ok, but it's working).

My final problem: The UpdateProgress control is not displaying for the queued requests. Any idea how to make this work??

Thanks,

Fred

multiple update panels each with a timer

I have a very simple page. It has 1 script manager and 2 update panels. Each update panel has a label and a timer. the timers are set 1 second and each simply updates the label with the current time. The first timer works and displays the time. The second never fires. Any one have any ideas? Here is the page...

<%

@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeBehind="Default.aspx.cs"Inherits="WebApplication1._Default" %>

<%

@dotnet.itags.org.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"Namespace="System.Web.UI"TagPrefix="asp" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headrunat="server"><title>Untitled Page</title>

</

head>

<

body><formid="form1"runat="server"><div><asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager>

</div> <asp:UpdatePanelID="UpdatePanelFirst"runat="server"><ContentTemplate><asp:TimerID="TimerFirst"runat="server"Interval="1000"OnTick="TimerFirst_Tick"></asp:Timer><asp:LabelID="LabelFirst"runat="server"></asp:Label></ContentTemplate></asp:UpdatePanel><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:TimerID="Timer1"runat="server"Interval="1000"OnTick="Timer1_Tick"></asp:Timer><asp:LabelID="Label1"runat="server"Text="Label"></asp:Label></ContentTemplate></asp:UpdatePanel></form>

</

body>

</

html>

and the code behind.

using

System;

using

System.Data;

using

System.Configuration;

using

System.Collections;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Web.UI.HtmlControls;

namespace

WebApplication1

{

publicpartialclass_Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protected

void Timer1_Tick(object sender,EventArgs e)

{

Label1.Text =

DateTime.Now.ToShortTimeString();

}

protectedvoid TimerFirst_Tick(object sender,EventArgs e)

{

LabelFirst.Text =

DateTime.Now.ToLongTimeString();

}

}

}

I am not sure about your requirement. If you are trying to update both the labels at the same time one timer will do.

But if you want both the Timer ticks to work modify your code as follows:

protected

void Timer1_Tick(object sender,EventArgs e)

{

Timer1.Enabled =

false;

Timer2.Enabled =

true;

Label1.Text = System.

DateTime.Now.ToLongTimeString();

}

protectedvoid Timer2_Tick(object sender,EventArgs e)

{

Timer2.Enabled =

false;

Timer1.Enabled =

true ;

Label2.Text = System.

DateTime.Now.ToLongTimeString();

}

multiple updatepanel which one is actived javascript

Hi all,

Title says everthing actually. I need to find which update panel is updating at the moment for multiple update panel coding which in one update panel i have coded to update others on the server side conditionally. If i cant find which one is activated is it possible to find which one initiated the update will work too. Thanks

Hi.

You can use UpdateProgress and associated the update panel with AssociatedUpdatePanelID property .

Hopes that help.


If I understand you correctly, you want to know on the client which UpdatePanel(s) were just updated.

If that's right, then take a look at the PageLoaded event on the PageRequestManager:http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/PageRequestManagerPageLoadedEvent.aspx.

You'll get two parameters passed to your handler... the second is a PageLoadedEventArgs:http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageLoadedEventArgsClass/default.aspx.

You can use args.get_panelsUpdated() to get an array of <div> elements that were just updated during an async postback.


actually both answers are not what I'm looking for if i read correctly. First i don't have UpdateProgress i use an generic modal that's called all over the place with out caller information. Its a function that shows please wait message like pleasewait(true); or false soAssociatedUpdatePanelID wont work since i don't have one.

And for your suggestion if i read this right, it works right after the update is ended, I need it while its working so i know if i want to abort it or not. Since one of the update is crucial not to stop, one is not crucial. So when i give them option to stop it should only stop if its not crucial. (if that make sense)

Im not sure but im going to try to set an hidden field with a value right when the update starts but didnt have time to test this one yet.


So you're looking to see what control is causing the update? (As opposed to which panels will be updated.)


no no i am look looking for which update panel is getting updated but i need to know it before or while the server side is getting called, like lets say we have updatepanel1, panel2 and panel3

they all call pleasewait(true) function to start the please wait modal window

I show a cancel button here but i only want this cancel button to work for updatepanel1 so need is it the panel one activing the please wait or panel2 or 3, so using the info i can disable the cancel button.

I hope that make sense.


But from your first post, aren't you making the decision about which UpdatePanels to update on the server? If so, there's no way to know on the client which panels will be updated, since that hasn't been decided yet.

In general, even if you're not doing anything explicit on the server (just using Triggers), all you can know on the client is which control is posting back. You won't know until the postback finishes which panels actually get updated.


Steve Marx:

But from your first post, aren't you making the decision about which UpdatePanels to update on the server? If so, there's no way to know on the client which panels will be updated, since that hasn't been decided yet.

Thats ok, i tought it would be the same tooo. So is possible to tell the second part of my question

drewex:

If i cant find which one is activated is it possible to find which one initiated the update will work too

As long as i can find which one initiates the update i think i can make this work.


I'll add one more thing there are iframes that i use in this page which can call the please wait too. So i need to seperate those too. But if there is not updatepanel update initiated that means iframe called it. so i can give cancel option or not. I hope im making some sense.

Multiple updatepanels and updateprogress

Hi,

I have created two updatepanels with a button and a label in each panel. Both panels are associated to a updateprogress. When I click the button I simle add datetime.now to the label. I also use thread.sleep for some seconds. This is a basic asp.net ajax example. But my question is: when I click the first button and thereafter click the second button when the first one is at sleep. In this case the second updateprogress starts working and I get the date in the second label. How can I manage to implement two asynchronous calls at the same time? i.e. I want to press both buttons and get two dates in each label.

You can't execute two partial postbacks simultaneously.

In InitializeRequest, you can use PageRequestManager.get_isInAsyncPostBack() to test for an already running partial postback and respond accordingly.


Ok, thank you. My question is answered!

Multiple UpdateProgress on a page?

My UpdateProgress Panel gets fired when I use my modalpopup box. Is there anyway for the modal popup to have its own progress and not trigger the one already defined on the page?

If you define aasp:UpdateProgressin a web form and specify an AssociatedUpdatePanelID?property for it, it will be triggered?and?display?the?
AssociatedUpdatePanel when you press any control in the web form.
Try the following codes and check if it works in your project.
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(InitializeRequest);
prm.add_endRequest(EndRequest);
var postBackElement;
function InitializeRequest(sender, args) {
if (prm.get_isInAsyncPostBack())
{
args.set_cancel(true);
}
postBackElement = args.get_postBackElement();
if (postBackElement.id == 'ButtonTrigger')
{
$get('UpdateProgress1').style.display = "block";
$get('ButtonTrigger').style.display = "none";
}
}
function EndRequest (sender, args) {
if (postBackElement.id == 'ButtonTrigger')
{
$get('UpdateProgress1').style.display = "none";
$get('ButtonTrigger').style.display = "block";
}
}
function AbortPostBack() {
if (prm.get_isInAsyncPostBack()) {
prm.abortPostBack();
}
}
</script
<div>
<asp:Button ID="ButtonTrigger" runat="server" Text="Refresh Panel 5" OnClick="Button_Click" />
<asp:UpdatePanel ID="UpdatePanel5" runat="server">
<ContentTemplate>
<%=DateTime.Now.ToString() %> <br />
The trigger for this panel
causes the UpdateProgress to be displayed
even though the UpdateProgress is associated
with panel 2.
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ButtonTrigger" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel6" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<%=DateTime.Now.ToString() %> <br />
<asp:Button ID="Button2" runat="server" Text="Refresh Panel 6" OnClick="Button_Click"/>
</ContentTemplate>
</asp:UpdatePanel>
<span style="display: inline-block;">
<asp:UpdateProgress ID="UpdateProgress1" runat="server">
<ProgressTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/airplane.bmp" />
</ProgressTemplate>
</asp:UpdateProgress>
</span>
</div>
Wish the above can help you.

multiple updatepanels, AsyncPostbackTrigger fails when referenced from more then 1 panel

Im using the latest Beta1, both core and CTP and toolkit, none of the old dll's exist on the system

Im not sure if the following issue is by design or if its a bug,


I have 3 updatepanels on the page, call them p1, p2 and p3 to make it easy to understand
first 2 panels contain a gridview, and a few other controls, p3 contains a couple of dropdowns and a linkbutton (lnk_insert)
when lnk_insert is clicked a new row gets added to gridview in p2 and the updatepanel forp2 contains the following trigger

<Triggers>
<asp:AsyncPostbackTrigger ControlID="lnk_insert" EventName="Click" />
</Triggers
the codebehind takes care of the database stuff and rebinds grid in p2, the page displays correctly and the trigger works fine so far, p2 gets updated
now the trouble - p1 contains a grid as well, whose data depends on grid in P2 (some summary info), the data gets prepared & returned correctly, (verified via debug) and is bound to grid via gridviewXXX.Databind,
p1 updatepanel contains the same

<Triggers>
<asp:AsyncPostbackTrigger ControlID="lnk_insert" EventName="Click" />
</Triggers
referencing the same link button, howeverp1does not update its contents,
different render modes in panel, and forced update of p1 via codebehind didnt help

no error messages come up, no javascript errors in browser either

which makes me think, is it possibly to reference the same control from 2 different updatepanels via asynctrigger ? or is one just overwriting the hooks to the other and thats why one of them doesnt trigger the refresh,

any tips ? thanks in advance

hello.

triggers can be associated with several panels. the following sample demonstrates that:

<%@. Page Language="C#" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
<script runat="server"
</script
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" id="manager" />
<asp:UpdatePanel runat="server" ID="panel1" UpdateMode="Conditional">
<ContentTemplate>
<span>UpdatePanel 1: <%=DateTime.Now.ToString( ) %></span>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="bt" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

<asp:UpdatePanel runat="server" ID="panel2" UpdateMode="Conditional">
<ContentTemplate>
<span>UpdatePanel 2: <%=DateTime.Now.ToString( ) %></span>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="bt" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

<asp:UpdatePanel runat="server" ID="panel3" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<span>UpdatePanel 3: <%=DateTime.Now.ToString( ) %></span>
<asp:LinkButton runat="server" ID="bt" Text="Refresh" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

can you build a small sample that reproduces the problem you're having?


Thanks for the prompt response and code sample, I figured out the problem, (I glued my code into your sample app , which helped locate the problem - it was my fault)

one of the databind's was pointing to the wrong grid - the 3 updatepanels work together as expected and have 2 triggers each

very nice, the attached is the full page, - certainly it wont run without the codebehind, but thats quite lengthy

bottom line multiple updatepanel can have multiple triggers even if (some) of the triggers reference the same control - works fine

<Triggers>

<asp:AsyncPostBackTriggerControlID="bt"EventName="Click"/>

<asp:AsyncPostBackTriggerControlID="gv_group"EventName="SelectedIndexChanged"/>

</Triggers>

<%@.PageLanguage="vb"AutoEventWireup="false"CodeBehind="3updatepanels.aspx.vb"Inherits="schedule._3updatepanels"StylesheetTheme="Default" %>

<%@.RegisterSrc="../controls/nav_main.ascx"TagName="nav_main"TagPrefix="uc1" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerrunat="server"id="manager"/>

<uc1:nav_mainID="Nav_main1"runat="server"/>

<divclass="filter">

<tableborder=1cellspacing=1cellpadding=1width=100%align=center>

<tr>

<td><h2>Groups</h2></td>

<td>Group Name

<asp:TextBoxID="txt_groupname"runat="server"></asp:TextBox></td>

<td>Contains Resource

<asp:DropDownListID="dd_resource"runat="server"AppendDataBoundItems=TrueDataSourceID="dsrc_resourcenames"DataTextField="name"DataValueField="pk_resource">

<asp:ListItemText="All"Value="0"></asp:ListItem>

</asp:DropDownList></td>

<td> Total Items =

<asp:LabelID="lbl_numItems"runat="server"></asp:Label></td>

<td>

<asp:ImageButtonID="btn_refresh"runat="server"ImageUrl="~/images/loader_36.gif"/></td>

</tr>

</table>

</div>

<asp:UpdatePanelrunat="server"ID="panel1"UpdateMode="Conditional">

<ContentTemplate>

<span>UpdatePanel 1: <%=DateTime.Now.ToString( ) %></span>

<asp:GridViewID="gv_group"runat="server"AutoGenerateColumns="False"DataKeyNames="pk_groupname"

DataSourceID="ds_groups"SkinID="BlueSky"AllowSorting=True>

<Columns>

<asp:CommandFieldShowSelectButton="True"/>

<asp:BoundFieldDataField="name"HeaderText="Group Name"SortExpression="name"/>

<asp:BoundFieldDataField="NumItems"HeaderText="Number of Resources"ReadOnly="True"SortExpression="NumItems"ItemStyle-HorizontalAlign=Center/>

<asp:CommandFieldShowDeleteButton=TrueButtonType=ImageDeleteImageUrl="~/images/cancel.gif"ShowEditButton=TrueEditImageUrl="~/images/edit.gif"CancelImageUrl="~/images/cancel.gif"UpdateImageUrl="~/images/confirm_16.gif"/>

</Columns>

</asp:GridView>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="bt"EventName="Click"/>

<asp:AsyncPostBackTriggerControlID="gv_GroupResources"EventName="RowCommand"/>

</Triggers>

</asp:UpdatePanel>

<tablewidth="100%"cellpadding="0"cellspacing="1"bgcolor="gainsboro">

<tr>

<tdbgcolor="whitesmoke"height="25"><imgid="plusminus"src="../images/plus.gif"align="absMiddle"/>

<b>Add New Group :

<asp:TextBoxID="txt_insertname"runat="server"></asp:TextBox>

<asp:LinkButtonID="btn_insert"runat="server">Insert</asp:LinkButton>

</b>

<asp:LabelID="lbl_msg"runat="server"EnableViewState="False"ForeColor="Red"></asp:Label>

</td>

</tr>

</table>

<asp:ObjectDataSourceID="ds_groups"runat="server"DeleteMethod="Delete"InsertMethod="Insert"

SelectMethod="GetDataByWhere"TypeName="schedule.MainTableAdapters.T_GroupNameTableAdapter"

UpdateMethod="Update">

<DeleteParameters>

<asp:ParameterName="pk_groupname"Type="Int32"/>

</DeleteParameters>

<UpdateParameters>

<asp:ParameterName="pk_groupname"Type="Int32"/>

<asp:ParameterName="name"Type="String"/>

</UpdateParameters>

<InsertParameters>

<asp:ParameterName="name"Type="String"/>

<asp:ParameterDirection="InputOutput"Name="pk_groupname"Type="Object"/>

</InsertParameters>

<SelectParameters>

<asp:ParameterName="WhereCondition"Type=string/>

<asp:ParameterDefaultValue="[name]"Name="OrderByExpression"Type="String"/>

</SelectParameters>

</asp:ObjectDataSource>

<asp:SqlDataSourceID="dsrc_resourcenames"runat="server"CacheDuration="120"ConnectionString="<%$ ConnectionStrings:schedule.My.MySettings.conn_Schedule %>"

EnableCaching="True"SelectCommand="SELECT [pk_resource], [name] FROM [T_Resource] ORDER BY [name]">

</asp:SqlDataSource>

<br/>

<tablewidth="100%"cellpadding="0"cellspacing="1"bgcolor="gainsboro">

<tr>

<tdbgcolor="whitesmoke"height="25"><imgid="Img1"src="../images/plus.gif"align="absMiddle"/>

<b>Resources Part of This Group :</b>

</td>

</tr>

</table>

<asp:UpdatePanelrunat="server"ID="panel2"UpdateMode="Conditional">

<ContentTemplate>

<span>UpdatePanel 2: <%=DateTime.Now.ToString( ) %></span>

<asp:GridViewID="gv_GroupResources"runat="server"AutoGenerateColumns="False"

DataSourceID="dsrc_groupresources"SkinID=BlueSkyDataKeyNames="pk_group2resource">

<EmptyDataTemplate>

<h3>None.</h3>

</EmptyDataTemplate>

<Columns>

<asp:CommandFieldShowDeleteButton="True"DeleteText="Remove"/>

<asp:BoundFieldDataField="name"HeaderText="Name"SortExpression="name"/>

<asp:TemplateFieldHeaderText="Location"SortExpression="fk_location">

<ItemTemplate>

<%#lookup.L_Location(Eval("fk_location") - 1)("name").ToString%>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="OutputType"SortExpression="fk_outputType">

<ItemTemplate>

<imgborder=0src='../images/<%#lookup.Outputtype(Eval("fk_outputtype")-1)("icon").ToString%>'align=absbottom/>

<%#lookup.Outputtype.Item(eval("fk_outputtype")-1)("outputtype").ToString %>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="Status"SortExpression="fk_status">

<ItemTemplate>

<imgborder=0src='<%#GetResourceStatus(Eval("fk_status"), "icon")%>'align=absbottom/>

<%#GetResourceStatus(Eval("fk_status"),"name")%>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateFieldHeaderText="Type"SortExpression="fk_type">

<ItemTemplate>

<imgborder=0src='<%# getResourceType(Eval("fk_type"),"icon") %>'align=absbottom/>

<%# getResourceType(Eval("fk_type"),"name") %>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="bt"EventName="Click"/>

<asp:AsyncPostBackTriggerControlID="gv_group"EventName="SelectedIndexChanged"/>

</Triggers>

</asp:UpdatePanel>

<asp:ObjectDataSourceID="dsrc_groupresources"runat="server"DeleteMethod="Resource_DeleteFromGroupbyPK"

SelectMethod="GetData"

TypeName="schedule.MainTableAdapters.Resource_SelectGroupbyGroupPKTableAdapter">

<DeleteParameters>

<asp:ParameterName="pk_group2resource"Type="Int32"/>

</DeleteParameters>

<SelectParameters>

<asp:ControlParameterControlID="gv_group"Name="pk_group"PropertyName="SelectedValue"

Type="Int32"/>

</SelectParameters>

</asp:ObjectDataSource>

<br/>

<tablewidth="100%"cellpadding="0"cellspacing="1"bgcolor="gainsboro">

<tr>

<tdbgcolor="whitesmoke"height="25"><imgid="Img2"src="../images/plus.gif"align="absMiddle"/>

<b>Add Resource to this Group :</b></td>

</tr>

<tr>

<td>

<divid="divAdd"style="DISPLAY:inline;">

<asp:UpdatePanelrunat="server"ID="panel3"UpdateMode="Conditional"ChildrenAsTriggers="false">

<ContentTemplate>

<span>UpdatePanel 3: <%=DateTime.Now.ToString( ) %></span>

Filter Location :<asp:DropDownListID="dd_add_location"runat="server"AutoPostBack=trueAppendDataBoundItems=trueOnSelectedIndexChanged="dd_add_location_SelectedIndexChanged">

<asp:ListItemText="All"Value="0"></asp:ListItem>

</asp:DropDownList>

Filter OutputType :

<asp:DropDownListID="dd_add_outputtype"runat="server"AutoPostBack=trueAppendDataBoundItems=trueOnSelectedIndexChanged="dd_add_outputtype_SelectedIndexChanged">

<asp:ListItemText="All"Value="0"></asp:ListItem>

</asp:DropDownList>

<br/>

Resource Name :

<asp:DropDownListID="dd_add_resource"runat="server"DataSourceID="dsrc_filter_resources"DataTextField="name"DataValueField="pk_resource">

</asp:DropDownList>

<asp:LinkButtonID="btn_add_resource"runat="server"OnClick="btn_add_resource_Click">Add to Group</asp:LinkButton>

<asp:LabelID="lbl_msg2"runat="server"EnableViewState="False"ForeColor="Red"></asp:Label>

<asp:LinkButtonrunat="server"ID="bt"Text="Refresh"OnClick="bt_Click"/>

</ContentTemplate>

</asp:UpdatePanel>

</div></td>

</tr>

</table>

<asp:SqlDataSourceID="dsrc_filter_resources"runat="server"ConnectionString="<%$ ConnectionStrings:schedule.My.MySettings.conn_Schedule %>"

DataSourceMode="DataReader"SelectCommand="SELECT [pk_resource], [name] FROM [T_Resource] ORDER BY [name]">

</asp:SqlDataSource>

</form>

</body>

</html>


When you have multiple UpdatePanels having the same Trigger, all of the update panels will update, but is the processing really async or not? I am asking as I need to have one trigger ('search button') which triggers updating multiple UpdatePanels, AND I would like to detect when each of the UpdatePanels has been updated so I can indicate this outside of the individual UpdatePanels (each UpdatePanel has an associated 'tab' where an animated image displays while the request is running). The PageRequestManager (and it's endRequest) does not seem to help as it will only fire once (with an array of the names of all of the updated UpdatePanels available). I would like a way to trigger separate 'requests' (and react to the ending of each one separately). Thoughts?
hello.
nop. they're all updated udring the same postback. that's why you're getting the results you describe.

Multiple updates with Ajax

I have two dropdownboxes, one that is dependent on the other for the value. I have these dropdown boxes in an update panel using a sqldatasource on both of them. The second dropdown box uses the selected value from the first dropdown box to populate its content. I also have two text boxes that are start and end dates that are based on the second dropdown box. For further clarification, I have a publication dropdown box that will populate the issue dropdown box with a listing of all issues for that publication and also will populate the start and end dates for that issue. However, when I select a different publication and the issue is on another month, the issue then is updated but not the start and end dates. How would I go about accomplishing this?

//

//

Publication: ARCHI-TECH Buildings Interiors and SourcesIssue: April 2007 March 2007 January 2007 January/February 2007 December 2006 November/December 2006 October 2006 September 2006 September/October 2006 July 2006 July/August 2006 June 2006 May/June 2006 March/April 2006 January 2006 January/February 2006 November 2005 November/December 2005 September/October 2005 July 2005 July/August 2005 June 2005 May 2005 May/June 2005 April 2005 March/April 2005 February 2005 January 2005 January/February 2005 December 2004 November 2004 November/December 2004 September/October 2004 August 2004 July/August 2004 May/June 2004 March 2004 February 2004 January 2004*Section: Please Select a Section Awards Bottom Line Energy Issues Career CaseStudy CoverStory FastTalk Feature Innovations Awards - 2001 Innovations Awards - 2002 Interior Design Award - 2001 Interior Design Award 2002 News NextPage OnlineExclusive Opinion Product Smarter SmarterBuildings SubArticle TechWork theBuzz ViewPoint Who'sWho

Start Date:**End Date:**

Can you post the ASPX, or explain how you have this set up? Are the textboxes inside of the updatepanel? Do you have the textboxes in a separate updatepanel that has a trigger set? Are you updating the textbox values in the page_load event? You should try stepping through your code, and ensure that the code responsible for setting the text in the textboxes is actually being reached. If it is, verify that the textboxes are inside of an update panel. Control outside of the updatepanel can not be udpated asynchronously (unless insdie of another updatepanel).

Monday, March 26, 2012

Multiview and Javascript in a view.

Hi, I am using a Multiview control in an update panel, and I need to output some dynamic Javascript inside a View control. Please see below.

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Height="478px" Width="557px">
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">


</asp:View>
<asp:View ID="View2" runat="server">

<script type="text/Javascript">//<![CDATA[
function aa(){alert('<%= DateTime.Now %>');}
//]]></script>
<input type='button' onclick='aa()' />

</asp:View>
</asp:MultiView>
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" /></asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

--BEHIND--

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
}
}

The problem is, that when you click the button that runs the function "aa", an "Object expected" error is thrown. Presumably because the newly outputted script has not been 'registered' with the browser (I checked with Nikhils Web Dev Helper and the script is present).

As I say, the script is dynamic, so I can't move it to an external file, nor would it be good to have to write the script outside of the Multiview (since it's dependent on the controls in View).

Any help or tips greatly welcome - thanks,

Jim


Read this, will give you solution.

http://forums.asp.net/thread/1502486.aspx

WS


Thanks, that did help with my example -however...

In reality my UpdatePanel and Multiview are inside a UserControl. So I dont have access to ScriptManager from the UserControl.

I looked at ScriptManagerProxy, but that doesn't have the RegisterClientScriptBlock method :(

Any idea how I can do this from within a UserControl?

Many thanks

Jim


Is this your code behind from your UserControl?

protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
}

??

You can add

protected void Button2_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View2);
System.Web.UI.ScriptManager.RegisterClientScriptBlock ...
}

It works on my end ... should be the same on yours.

WS


AHH! RegisterClientScriptBlock is static - sorry I assumed it wasn't.

Yes that works great, thanks very much - you saved me some awkward workarounds.

Smile

Jim


Can I open up this topic, and add a little twist to it?

I have u panel inside a multiview, this panel has a usercontrol which shows a HTML page from a database (response.binarywrite because it's all blobs) I hav e NO control of the javascript that is used in the HTML files that are loaded from the database.

One of the HTML files that is loaded, contains javascript to have a menu with hoverfunctions enabled on the html-page:

if (window.attachEvent) window.attachEvent("onload", sfHover);

When I switch the multiview.activeindex, back and forth to the panel with the usercontrol, the hover functions do not work anymore...anyway, in IE they don't. In Firefox they do work.

The RegisterClientScriptBlock is no option, because I am not aware of the javascript functions that are used in the database-files.

I hope my explanation is clear...

Rob

Mutiple update panel - How to bind trigger event for control which is inside of other upda

Hi,

Thanks for visitng my problem.

I have 3 update panels. in first update panel U1 I have text box T1 and drop dwonbox D1.In second update panel U2 i have only drop down box D2. and in third update panel U3 i have a treeview T1.

I want that When I change selection of D1 in U1, it triiger events for D2 in U2 and T1 in U3. But when I try to bid U2 with D1 change event it does not show show D1 namein triiger control names. Rather it shows U1 panel name. Sam case is for T1 in U3. So my qiestion is : "HOW TO BIND TRIGGER WITH CONTROL WHICH IS INSIDE OF OTHER UPDATE PANEL?"

Looking for your Help.

Thanks,

John

Hi John,

I think the easiest solution would be to place one UpdatePanel around all three controls. If this doesn't work for you, perhaps you could post asmall code sample showing what you already tried.

Thanks,
Ted

MutuallyExclusiveCheckBoxExtender in Panel in Updatepanel in Repaeter!

Hi,

I've used this site for reference many times (coz i'm that good!) but this is my first post, so thanks for all the help guys!

Anyway...

I have a page with a repeater control. inside the repeater, i have an updatepanel (i don't need the whole repeater refreshed), and inside that, i have 2 checkboxes that i want to be mutually exclusive!

straightforward huh? er...no!!

adding the MutuallyExclusiveCheckBoxExtender to the panel at Design time causes ALL the checkboxes to uncheck when you click on one, and i can't seem to add the MECE's dynamically at runtime - when i click, nothing happens.

Here's some code for you... it's placed inside Repeater_ItemDatabound

//Check the boxes depending upon user's role Panel myPanel = e.Item.FindControl("RolePanel")as Panel;if (myPanel !=null) { CheckBox myCbA = myPanel.FindControl("cbAdmin")as CheckBox;if (myCbA !=null) { myCbA.Checked = Roles.IsUserInRole(myUser,"Administrator"); } CheckBox myCbB = myPanel.FindControl("cbUser")as CheckBox;if (myCbB !=null) { myCbB.Checked = Roles.IsUserInRole(myUser,"User"); }//Add some ajax! AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender MeCeA =new AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender(); AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender MeCeB =new AjaxControlToolkit.MutuallyExclusiveCheckBoxExtender(); MeCeA.ID ="MeCeA" + ItemCount.ToString(); MeCeA.Key ="Roles" + ItemCount.ToString(); MeCeA.TargetControlID = myCbA.ID; MeCeB.ID ="MeCeB" + ItemCount.ToString(); MeCeB.Key ="Roles" + ItemCount.ToString(); MeCeB.TargetControlID = myCbB.ID; myPanel.Controls.Add(MeCeA); myPanel.Controls.Add(MeCeB); }

and the source... placed inside the RepeaterItem ItemTemplate

<ajax:UpdatePanel ID="UserDetailsUpdatePanel" runat="server" UpdateMode="Always"> <ContentTemplate> <cc1:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="lblResponse"> <Animations> <OnLoad> <FadeOut Duration=".5" Fps="20" /> </OnLoad> </Animations> </cc1:AnimationExtender> <div class="RolePanel"> <asp:Panel ID="RolePanel" runat="server"> <asp:CheckBox ID="cbAdmin" runat="server" Text="Administrator" AutoPostBack="true" /><br /> <asp:CheckBox ID="cbUser" runat="server" Text="User" AutoPostBack="true" /><br /> <center><asp:LinkButton ID="lbtnRoles" runat="server" Text="Submit" /></center> <center><asp:Label ID="lblResponse" runat="server" Visible="False" /></center> </asp:Panel> </div> </ContentTemplate> </ajax:UpdatePanel>

I hope someone can help me - this ajax stuff makes my sites look and feel all funky!

TIA

Ché

Seriously... is there no-one who can help me?

Hi,

If I understand the question correctly, you want all 2 to be mutually exclusive checkboxes.

Have you tried adding 2 MutuallyExclusiveCheckBoxExtender in design mode and specifying the same key for both of them?


Yep, i tried that, but where it's inside a repeater it clears all the checkboxes including ones in the different repeateritems.

so, i had the brilliant idea of dynamically creating the extenders at runtime and giving each pair a key, also created at runtime so it's different for each repeateritem.

didn't work.*sob*

so then i thought of grabbing each extender as the repeateritem was databound and applying the unique key there...

nope - didn't work!

Take a quick look at this...


once, i thought it'd be simple!!

TIA for any help!!

Ché


Sorted It!!

one of my plans was indeed correct - i didn't set a key in design time, then at runtime, i grabbed the two extenders and set a unique key for them on each RepeaterItem_DataBound.

Job done!!


My (Un)Modal Popup

I have added a modal popup to my user control. I show the modal popup by registering a startup script in the code-behind of an update panel trigger. The modal popup appears, but it isn't modal. I can click and edit the form fields behind the modal popup. Has anyone seen this happen? Any thoughts on how to fix it?Post code and I might be able to help you

Have you set the BackgroundCSSClass properly? I saw the same behavior and was able to fix it by setting the BackgroundCSS... here's an example of the CSS I used

.modalBackground

{background-color:Gray;filter:alpha(opacity=70);

}


I used below css but still my main page controls can be accessed?

.modalBackground

{background-color:Gray;filter:alpha(opacity=70);

}

This is happening in (Un)Modal fashion, any have solution for this.

Saturday, March 24, 2012

My gridview is not update

Hi,

I have an update panel in my page which contain a grid view.

I need to refresh my page periodically. I am using Timer for that. Here is my code

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:TimerID="Timer1"runat="server"Interval="10000">

</asp:Timer>

...................

<asp:GridViewID="GridView1"runat="server"SkinId="SampleGridView"CssSelectorClass="PrettyGridView"

DataKeyNames="ID"DataSourceID="SqlDataSource2"OnSelectedIndexChanged="GridView1_SelectedIndexChanged"

OnRowCommand="VerDiagramRed"Width="666px"OnDataBound="GridView1_DataBound"AutoGenerateColumns="False">

<Columns>

<asp:CommandFieldShowSelectButton="True"SelectText="Routers"/>

<asp:BoundFieldDataField="ID"HeaderText="ID"InsertVisible="False"ReadOnly="True"

SortExpression="ID"/>

<asp:BoundFieldDataField="Nombre"HeaderText="Nombre"SortExpression="Nombre"/>

<asp:BoundFieldDataField="Lectura"HeaderText="Lectura"SortExpression="Lectura"/>

<asp:BoundFieldDataField="Errores"HeaderText="Errores"SortExpression="Errores"/>

<asp:BoundFieldDataField="Estado"HeaderText="Estado"SortExpression="Estado"/>

<asp:ButtonFieldButtonType="Image"CommandName="diagram"HeaderText="Plano"

Text="Diagrama"ImageUrl="~/images/diagrama1.jpg"/>

</Columns>

</asp:GridView>

</ContentTemplate></asp:UpdatePanel>

DataGrid is not refreshed. What am doing wrong?

Thank you

Hi!

Follow these steps and it should work:

- Take the Timer out of the UpdatePanel.
- Set the UpdatePanel's properties UpdateMode="Conditional" and ChildrenAsTriggers="false"
- Add a trigger to the UpdatePanel's triggers collection:

<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="OnTick" />
</Triggers>

Now, as you are doing something on OnSelectedIndexChanged and OnRowCommand, are you sure that you need the Timer at all? Is not enough to refresh the GridView on these events?

Anyway, don't forget to add triggers for each event you are handling.

Hope this helps,



You can use Timer Control & you can trigger it's OnTick event..

So that it will periodically refreshes the GridViewSmile


Thank you very much. I did what you said and it is working perfectly.

I need to do refresh periodically because the users needs to monitor the information in the gridview.

my javascript method not working with update panel

Hi All,

The gridview (inside a user control) i am using in my screen (.aspx page) have a Checkbox column in the end. When i click the checkbox in the header all the checkboxes are selected. (A long javascript code has been written for that in the user control)

Now I have applied a scriptmanager and update Panel on this user control, and since then the javascript which selects all the checkboxes is not working properly.

I would like to know what i can do to resolve this javascript issue. And also would like to know why using the basic tools of ASP.NET AJAX control is stopping my own javascript from firing.

Please Note: On leaving a validation on page, the page postback and shows the validation. After this the javascript of Gridview works fine.

I have tried searching on google, but was not able to find any satisfactory explanation to my problem. It would be great if you people can help me.

Thanks,

Shikha

Please post your source code.


Hi,

Thank you for your post!

It is normal when you place inline javascript in an undatepanel/

For more information and solution, seeUpdatePanel and Rendered (Inline)Javascript

It seems that the UpdatePanel essentially replaces the InnerHTML of a DIV with the delta returned from the server. If you try this yourself you will notice that any javascript elements in the html are not fired.

All javascript registered on the server-side (if you are using .NET) with the ScriptManager is put into a separate section of the returned delta. The atlas runtime obviously then loads these scripts into the document manually.

What if the returned HTML has Javascript tags already rendered in it? Nothing.:(
Such was our predicament and we had no control over the HTML that would be returned to the UpdatePanel (ReportViewer Control). Could we manually load the javascript ourselves when the UpdatePanel returns the payload? As it turns, we could.

You can create script elements on the fly and they get evaluated as you do. Atlas has the ScriptLoader object that will do it for you if your JavaScript is an external reference. Tweaking this idea we got a solution that found all the new Script elements and added them to the document.

If you have further questions,let me know.

Best Regards,

Navigation using Master pages and Update panel without refresh

Hi

I have a master page in which there are hyperlinks to go to different pages. Its a header basically. I got the relevant content pages for the hyperlinks.

But when I click the master page links, a postback occurs and the whole page is refreshed and directed to the new page.

I need a way by which when I click the hyperlinks in master page the content pages change without any refreshing. I heard about the Iframe implementaion in update panel is it a feasible way to do this or multiview might solve my problem ?

Having a master page sort of defeats the purpose of keeping the same page and dynamically updating portions on postback. The master page is meant to be a supplement for the page the user is viewing. This means the master page is never browsed directly, it only contains master code for each of the pages that are browsed to directly.

Also, hyperlink controls should not perform postbacks -- they are simply meant for navigation. Therefore, anytime a user clicks a hyperlink, the user will be taken to the new page, causing flicker. I suggest using a link button instead. These perform postbacks and can capture events much better than a hyperlink.

In order to do what you're trying to do, consider not using a master page. Instead, use a single page that makes use of either an iframe or a multiview enclosed in an updatepanel. Example is below:

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="theForm"runat="server">
<divid="wrapper">
<asp:ScriptManagerID="scriptManager"runat="server"></asp:ScriptManager>
<divid="header">
<asp:LinkButtonID="lnkClickMe"runat="server"OnClick="lnkClickMe_Click">Click Me!</asp:LinkButton>
</div>
<asp:UpdatePanelID="pnlDynamicContent"runat="server"UpdateMode="Conditional">
<ContentTemplate>
<asp:MultiViewID="mvDynamicContent"runat="server"ActiveViewIndex="0">
<asp:ViewID="viewBeforeClick"runat="server">
This is before the link above is clicked
</asp:View>
<asp:ViewID="viewAfterClick"runat="server">
This is after the link above is clicked
</asp:View>
</asp:MultiView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTriggerControlID="lnkClickMe"EventName="Click"/>
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

And the code-behind:

PartialClass Test_ForumTest
Inherits System.Web.UI.Page

ProtectedSub lnkClickMe_Click(ByVal senderAsObject,ByVal eAs EventArgs)
mvDynamicContent.ActiveViewIndex = 1
EndSub
EndClass


Convert your hyperlink to linkbuttons then register these buttons as AsyncTrigger in the Update Panel. Convert Your Content Pages to User Control. Load the Proper User Control on Button Click.

Need a little help with the Tab Panels

I'm having a problem with Tab Panels jumping around that I need a little help with. I have 4 Tab Panels in which each Tab Panel contains a DataGrid Control with paging and 1 Tab Panel with a FormView Control also with paging enabled. Here is what happens, when I first enter the web page if I'm on say Tab Panel 2 which contains a DataGrid with paging enabled and then click Tab Panel 1 which also contains a DataGrid with paging enabled and click 2 to go to the next page of data in the DataGrid it jumps back over to Tab Panel 2 which is the first Tab I started out on when the page displayed.

I'm not sure why or how to correct this issue of the DataGrid/FormView paging causing the Tab Panels to jump instead of staying on that Tab Panel as I page through the data until I actually click on a different Tab Panel.

ASP.NET AJAX Control Toolkit - Tab Control - Postback on tab switch


Thanks, that works fine.


Hi Lspence,

I want to design a Tab control with 5 tabs based on userId.. and each tab will be populated with a datagrid... based on the UserId clicked.. so do i need to have different Datagrids for each tab.. or can i just have one datagrid in the first tab and then call the same Datagrid based on the UserId given..

any help will be appreciated on this,,

Regards

Karen


I maybe wrong, but I think you can use a single DataGrid and just change your DataSource to a different one on each Tab. I have not tried doing something as you are doing, so someone else might be able to chime in on this approach.

Lspence,

in your post u have mentioned

"I have 4 Tab Panels in which each Tab Panel contains a DataGrid Control with paging and 1 Tab Panel with a FormView Control also with paging enabled. Here is what happens, when I first enter the web page if I'm on say Tab Panel 2 which contains a DataGrid with paging enabled and then click Tab Panel 1 which also contains a DataGrid with paging enabled and click 2 to go to the next page of data in the DataGrid it jumps back over to Tab Panel 2 which is the first Tab I started out on when the page displayed."

did u use a seperate datagrid for your panels...and how did u handle it... pls give me ideas.

Regards

Karen


Sorry, yes you are correct in my previous post. I have a different DataGrid for each Tab Panel except for the last one which uses a FormView. I basically followed information provided by the previous poster. I used the following javascript.

<script type="text/javascript" language="javascript">
function ActiveTabChanged(sender, e)
{
// Use the client side active tab changed event to trigger a callback thereby triggering the server side event.
__doPostBack('<%= TabContainer1.ClientID %>', sender.get_activeTab().get_headerText());
}
</script>
I then put my entire TabContainer inside of an UpdatePanel and added the following to the TabContainer tag. 
<cc1:TabContainer ID="TabContainer1" runat="server" TabIndex="0" ActiveTabIndex="3" OnClientActiveTabChanged="ActiveTabChanged" >
I finally added the following in the Page_Load method. 
ScriptManager.RegisterAsyncPostBackControl(TabContainer1);
That's all. 


Thanks for your answer... can u please give some code of your..tab panel.. cause i am creating a datagrid inside the panel in the .aspx page and then i am hooking the datasource and everything else at the code behind.. so just wanted to check if whatever i am doing is right or not...

Is it also possible to have get header text automatically populated based on the userId's for the particular client..

any help will be appreciated.

Regards

Karen


No problem this example sets the DataGrid's DataSource in Design Mode.

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="true" %
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" /
<script type="text/javascript" language="javascript">
function ActiveTabChanged(sender, e)
{
__doPostBack('<%= SampleTabContainer.ClientID %>', sender.get_activeTab().get_headerText());
}
</script
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<cc1:TabContainer ID="SampleTabContainer" runat="server" ActiveTabIndex="1" TabIndex="0" OnClientActiveTabChanged="ActiveTabChanged">
<cc1:TabPanel ID="Panel1" runat="server" HeaderText="Panel1" >
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="First Name" InsertVisible="False" ReadOnly="True" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
<asp:BoundField DataField="ZipCode" HeaderText="Zip Code" SortExpression="ZipCode" />
</Columns>
<PagerSettings Mode="NextPrevious" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=.;Initial Catalog=TestDB;Integrated Security=True" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Customer]">
</asp:SqlDataSource>

</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="Panel2" runat="server" HeaderText="Panel2">
<ContentTemplate>
Different content. Could be another DataGrid.
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SampleTabContainer" EventName="ActiveTabChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(SampleTabContainer);
}
 

Spence,

Thanks for the code.. I am dynamically adding the Tab Panels using my code behind...

i have a datagrid in a user control which has pagin and sorting enabled and the data loads fine.. I am calling this UserControl in a tab panel using Ajax.. But when I Try to sort and page in my tab Panel...i get an error saying

specified argument was out of the range of valid values. Parameter name: Value

Hope u can help me solve it.. I am dynamically generating the Tabpanel and passing the valid values to load the user control.. but when i try to page and sort i get a popup with the above error..

Any help will be appreicated.

Regards

Karen