Showing posts with label repeater. Show all posts
Showing posts with label repeater. Show all posts

Wednesday, March 28, 2012

Context menus, Ajax and repeaters

I have been looking and looking for a context menu that can be applied to an asp:XXX object within a repeater. My problem with a lot of the context menus out there is they do not allow me to specify databind values to the menu items based on what row inside the repeater was right clicked. My needs are this: the elements inside the context menu must execute a function in the cs file. The menu must pass values from the element that was right-clicked such as name, ID etc. and it "should" be quick.

I have gotten hover menus working atm but they drag the system down if the repeater has a large dataset returned.

Hi,

I fail to reproduce the issue. Can you show me your code?


Hi, ongjt

We are changing the issue state to "No status" because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue state back to "Not Resolved". If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

Thank you!

Monday, March 26, 2012

ConfirmButton not working

Hi,

I have a page with an update panel and a repeater inside the panel. I have a multi view inside the repeater item template. In that multiview, I have a view with a delete button and a confirm button extender. When you click on the delete button, the confirm alert appears (not always), but at the same time an asyncrhonous postback occurs, the record is deleted by the code behind page and the page is refeshed, but you have not clicked 'OK' nor "Cancel" yet.

Note: Using Beta

Here is the web page:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Templates.aspx.cs" Inherits="Templates" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="sm" runat = "server" />
<asp:ObjectDataSource ID="CategoriesDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetCategories" TypeName="DataLayer.ProtocolCategory"></asp:ObjectDataSource>
Select a category:
<asp:DropDownList ID="CategoriesDropDown" runat="server"
DataSourceID="CategoriesDataSource" DataTextField="CategoryName"
DataValueField="CategoryID" Width="250px"
AutoPostBack = "true" />
<br /><br /><hr /><br />
<asp:UpdatePanel ID="up" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:ObjectDataSource ID="TemplatesDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetTemplates" TypeName="DataLayer.ProtocolTemplate">
<SelectParameters>
<asp:ControlParameter ControlID="CategoriesDropDown" DefaultValue="0" Name="CategoryID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<table border="1" width="100%" >
<thead>
<tr>
<td align="center" colspan="4">Available templates</td>
</tr>
<tr>
<td width="25%">Name</td>
<td width="70%">Description</td>
</tr>
</thead>
<tbody>
<asp:Repeater ID="TemplatesRepeater" runat="server"
DataSourceID="TemplatesDataSource" OnItemCommand="TemplatesRepeater_ItemCommand" >
<ItemTemplate>
<tr>
<asp:MultiView ID="ItemMultiView" runat="server" ActiveViewIndex="0">
<asp:View ID="ReadOnlyView" runat = "server">
<td>
<asp:Label ID="NameLabel" runat="server"
Text= '<%# Eval("TemplateName") %>' />
</td>
<td>
<asp:Label ID="DescriptionLabel" runat="server"
Text = '<%# Eval("Description") %>' />
</td>
<td>
<asp:Button ID="EditButton" runat ="server"
CommandName="edit" Text="Edit" />
</td>
<td>
<asp:Button ID="DeleteButton" runat = "server" UseSubmitBehavior="false"
CommandName = "delete" Text= "Delete"
CommandArgument = '<%# Eval("TemplateID") %>' />
<ajaxToolkit:ConfirmButtonExtender ID ="ConfirmButton" runat="server"
ConfirmText = "You are about to delete this template. Click ok to proceed"
TargetControlID = "DeleteButton" />
</td>
</asp:View>
<asp:View ID="EditView" runat="server">
<td>
<asp:TextBox ID="NameTextBox" runat ="server"
Text= '<%# Eval("TemplateName") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text = '<%# Eval("Description") %>' />
</td>
<td>
<asp:Button ID = "SaveButton" runat = "server"
CommandName= "save" Text = "Save"
CommandArgument = '<%# Eval("TemplateID") %>' />
</td>
<td>
<asp:Button ID = "CancelButton" runat = "server"
CommandName = "cancel" Text = "Cancel" />
</td>
</asp:View>
</asp:MultiView>
</tr>
</ItemTemplate>
<FooterTemplate>
<td>
<asp:TextBox ID="NameTextBox" runat ="server"
Text= '<%# Eval("TemplateName") %>' />
</td>
<td>
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text = '<%# Eval("Description") %>' />
</td>
<td>
<asp:Button ID = "AddButton" runat = "server"
CommandName= "add" Text = "Add" />
</td>
</FooterTemplate>
</asp:Repeater>
</tbody>
</table>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CategoriesDropDown" EventName="SelectedIndexChanged" />
</Triggers>

</asp:UpdatePanel>
</div>
</form>
</body>
</html>

And a fraction of code behind:

protected void TemplatesRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "edit")
EditItem(e);
else if (e.CommandName == "cancel")
CancelItem(e);
else if (e.CommandName == "save")
SaveItem(e);
else if (e.CommandName == "delete")
DeleteItem(e);
else if (e.CommandName == "add")
AddItem(e);

}

private void DeleteItem(RepeaterCommandEventArgs e)
{
int TemplateID = int.Parse((string) e.CommandArgument);
DataLayer.ProtocolTemplate.DeleteTemplate(TemplateID);
this.TemplatesRepeater.DataBind();
}

I have removed the update panel, but still does not work.

The first time the page is rendered (HTTP GET) no AjaxControlToolkit.ConfirmButtonBehavior are created.

When you click on the delete button a regular postback occurs, the row is deleted and I get the following error on a browser alert:

Line: 1960
Error: Sys.ArgumentException:Value must not be null for Controls and Behaviors
Parameter name:element

The page source code contains the following javascript code:

Sys.Application.add_init(function() {
$create(AjaxControlToolkit.ConfirmButtonBehavior, {"ConfirmText":"You are about to delete this template. Click ok to proceed","id":"ConfirmButton"}, null, null, $get('DeleteButton'));
});
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.ConfirmButtonBehavior, {"ConfirmText":"You are about to delete this template. Click ok to proceed","id":"TemplatesRepeater_ctl00_ConfirmButton"}, null, null, $get('TemplatesRepeater_ctl00_DeleteButton'));
});
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.ConfirmButtonBehavior, {"ConfirmText":"You are about to delete this template. Click ok to proceed","id":"TemplatesRepeater_ctl01_ConfirmButton"}, null, null, $get('TemplatesRepeater_ctl01_DeleteButton'));
});

Obviously the first $create call fails because $get('DeleteButton') returns null since 'DeleteButton' does not exist.

If you continue clicking delete buttons you continue getting these errors, no confirmation alert message is shown.

Confirm button is the simplest control in Ajax Control Toolkit. I think at least this one should work :-(


I'm getting the exact same thing, except I am using a DataList instead of a Repeater.

I have decided not to use confirm button, instead I'm using the following:

 <script type="text/javascript"> function ConfirmDelete(e) { if (!window.confirm("You are about to delete this categorie.\nClick OK to proceed, cancel otherwise")) { e.returnValue = false; if (e.preventDefault) e.preventDefault(); return false; } } </script>
<asp:ImageButton ID="DeleteButton" runat ="server"
ImageUrl ="Images/delete.png" Height="16px" Width="16px"
CommandName ="delete" ToolTip="Delete"
CommandArgument ='<%# Eval("HospitalID")%>'
OnClientClick="ConfirmDelete(event);"
/>
Did this issue get resolved? I'm also finding that my ConfirmButton control is not in an Update panel.
Please try your scenario with the recently available10301 release of the Toolkit (andASP.NET AJAX 1.0). If the problem persists, then please reply with acomplete, simple, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

Saturday, March 24, 2012

Condition UpdatePanel being refreshed by asp:calendar postback

Hya,

I'm not sure the subject is appropriate but it's what i feel it's happening... I have a server control on UpdatePanel1 that pages a repeater, it his based on this article http://www.codeproject.com/aspnet/CollectionPager.asp although i made a few changes, now it inherits from a compositecontrol, and instead of prerendering the control it Creates Child Controls.


Ok now to the real issue, I have a popup calendar using the PopupControlExtender (having a few problems with the calendar from the toolkit http://forums.asp.net/thread/1547286.aspx) the calendar is inside a conditional updatepanel when the calendar postbacks the collectionpager in the other updatepanel is also refreshed!?!? e.g. it is initialized again and runs the createchildcontrols... Is this expected behaviour or am i doing something wrong?


this is the page code

<asp:Label ID="lblStartDate" runat="server" AssociatedControlID="start_date" Text="Start Date:"></asp:Label><br /> <asp:TextBox ID="start_date" runat="server" CssClass="frm_textbox" Width="150px" ValidationGroup="SearchLatestEvents"></asp:TextBox> <br /> <asp:Panel ID="PanelDatePicker" runat="server"> <asp:UpdatePanel ID="UpdatePanelDatePicker" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Calendar ID="CalendarDatePicker" SkinID="DatePickerSkin" runat="server" Width="160px" OnSelectionChanged="CalendarDatePicker_SelectionChanged"></asp:Calendar> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> <ajaxToolkit:PopupControlExtender ID="PopupControlDatePicker" TargetControlID="start_date" runat="server" PopupControlID="PanelDatePicker" Position="Bottom" /> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table border="1" cellpadding="3" cellspacing="0"> <tr> <th> Header1</th> <th> Header2</th> <th> Header3</th> <th> Header4</th> <th> Header5</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%# DataBinder.Eval(Container.DataItem, "Column1")%> </td> <td><%# DataBinder.Eval(Container.DataItem, "Column2")%> </td> <td><%# DataBinder.Eval(Container.DataItem, "Column3")%> </td> <td><%# DataBinder.Eval(Container.DataItem, "Column4")%> </td> <td><%# DataBinder.Eval(Container.DataItem, "Column5")%> </td> </tr> </ItemTemplate> <FooterTemplate> </TABLE> </FooterTemplate> </asp:Repeater> <lo9ik:CollectionPager ID="CollectionPager1" runat="server" OnClick="CollectionPager1_Click" PagingMode="PostBack" /> </ContentTemplate> </asp:UpdatePanel>

The repeater is being populated by some random data

I can provide the collectionpager code if you wish. But even reverting to the original version the problem persists so i don't think it's the changes i've done to it.

What's odder about all this is that it only happens when the calendar postbacks! could it be that AJAX is not detecting it's postbacks and is refreshing all the updatepanels??

Your help would be much appreciated...

regards,

Even simpler example:

 <asp:TextBox ID="start_date" runat="server" CssClass="frm_textbox" Width="150px" ValidationGroup="SearchLatestEvents"></asp:TextBox> <br /> <asp:Panel ID="PanelDatePicker" runat="server"> <asp:UpdatePanel ID="UpdatePanelDatePicker" ChildrenAsTriggers="true" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Calendar ID="CalendarDatePicker" SkinID="DatePickerSkin" runat="server" Width="160px" OnSelectionChanged="CalendarDatePicker_SelectionChanged"></asp:Calendar> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> <ajaxToolkit:PopupControlExtender ID="PopupControlDatePicker" TargetControlID="start_date" runat="server" PopupControlID="PanelDatePicker" Position="Bottom" /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"> <ContentTemplate> This panel should not be updated on date select!... <asp:UpdateProgress ID="UpdateProgress1" runat="server"> <ProgressTemplate> Updating... </ProgressTemplate> </asp:UpdateProgress> </ContentTemplate> </asp:UpdatePanel>

Code Behind:

protected void CalendarDatePicker_SelectionChanged(object sender, EventArgs e) { System.Threading.Thread.Sleep(3000); PopupControlDatePicker.Commit(CalendarDatePicker.SelectedDate.ToString("dd MMM yyyy")); }

Could please someone explain me what am i doing wrong? I have no triggers setup on UpdatePanel1, there's no reason for it to be updated when the calendar postback!!...

On my machine, UpdatePanel1 isnotbeing updated. I think you're being confused by the fact that your UpdateProgress control is showing. You probably want to put AssociatedUpdatePanelID="Update1" on it so that it only shows up when UpdatePanel1 is generating an async postback. Right now, since it's not associated with any particular UpdatePanel, it shows up on any async postback, so that's why you're seeing it appear.


Hi Steve,

Thanks for your contribution, I indeed realized that is true, but using the first example, my server control (collectionpager) still gets "refreshed"!... And that is actually what is causing the problems... On every createchildcontrols it goes through the pageddataset and adds the links/buttons for the functionality, because it is being "refreshed" and the dataset is not being databound it causes exceptions. I don't want to have to rebind the dataset everytime the calendar is used!..

I hope this makes things a bit clearer, if you want i can send you a full working example...


Kind Regards,


Maybe I understand... remember that when you use an UpdatePanel, there's an entire postback on the server. Try removing the UpdatePanels and get it to work that way first. From your last description, it sounds like your page won't work using regular postbacks, which means it also won't work when using async postbacks.


Spot on Steve, it was the way the control was built, it was databinding the repeater on it's onprerender method, causing it to create expections because the dataset was empty after a postback, i ended up removing the databind from within the control and instead use it to page the dataset and display the navigation...

So this means that all controls are in reality rendered again even if the postback is not for it's updatepanel!... It's slightly confusing as i expected that only the updatepanel to be updated should be "refreshed"...

Thanks for your help...


Glad you got it figured out!

Yup, during an async postback, the entire page gets rendered on the server, but only the part inside the UpdatePanel comes back down to the client.


Okay... so now we knowwhy it is happening. But is there any way to stop it happening? I have exactly the same issue.

It would be nice if there was some seperation and control over what UpdatePanels caused what UpdateProgresses to fire in the case where UpdatePanels are nested.

Or, a property on an UpdatePanel which simply says 'TriggerUpdateProgress' which can be set to false.

Wednesday, March 21, 2012

Concern.. Repeater Control and Update Panel.

Hello everybody,

How goodUpdatePanel withrepeater control? I am trying to use Repeator control ItemCommand" without a postback. but seems no effect. All I need is when a user click a perticular row in a repeator control "say a linkbutton", move a details panel (see below) into this user selected row with some information collected for that perticular row), this happen in "ItemCommand" event of repeator control. here is the server script..

Note I could easy done with Javascript and ClientPostBack but trying to do how good with Atlas .

please help.

<atlas:ScriptManagerrunat="server"ID="scriptsx"EnablePartialRendering="true"></atlas:ScriptManager>

<asp:repeaterid="Materials"runat="server"OnItemCommand="Repeater1_ItemCommand"><ItemTemplate>

<asp:panelrunat="server"id="rows">

<asp:LinkButtonid="LinkButton1"runat="server"CommandName="ShowIt"Text=<%# DataBinder.Eval(Container.DataItem, "Country")%>></asp:LinkButton>

</asp:panel></ItemTemplate></asp:repeater>

<atlas:UpdatePanelID="UpdateGrid"runat="server"Mode="Always"><ContentTemplate>

<asp:Panelrunat="server"ID="details"BackColor="gray"Visible="false">State Details</asp:Panel>

</ContentTemplate>

</atlas:UpdatePanel>

<Script runat="server">

protectedvoid Page_Load(object sender,EventArgs e){if (!IsPostBack){Materials.DataBind();}

}

protectedvoid Repeater1_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e){

details.Visible =

true;Panel p = (Panel)e.Item.FindControl("rows");

p.Controls.Add(details);}

</script>

thanks,

achu.

I think you just need to add in the Triggers section to your update panel as shown below:

<atlas:UpdatePanelID="UpdateGrid"runat="server"Mode="Always">
<ContentTemplate>
<asp:Panelrunat="server"ID="details"BackColor="gray"Visible="false">State Details</asp:Panel>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTriggerControlID="Materials"EventName="ItemCommand"/>
</Triggers>
</atlas:UpdatePanel>


Yep .. this does work. I have many Repeaters within UpdatePanels .. and Repeaters within Repeaters ..

Just make sure you sort out the triggers and make the panel conditional.

thank Paul & KFrancis

It is working now. It works when repeator control inside the UpdatePanel though. Also tried with multiple Repeator controls works like a charm!!.

Regards

achu

Compilation error UpdatePanel in Repeater

Hi,

I have a repeater with ItemTemplate and AlternativeTemplate. Within the repeater there is a Table. Inside of one of the <td> I have UpdatePanel, so in the ItemTemplate there is an UpdatePanel1 and there is another one in the AlternativeTemplate with the same ID name, I thought this won't have any conflict since we can put two controls with same ID as long as they are in the different Template. But I got this error :

Description:Anerror occurred during the compilation of a resource required to servicethis request. Please review the following specific error details andmodify your source code appropriately.

Compiler Error Message:CS0102: The type 'NamespaceName' already contains a definition for 'A_ControlName'

any help would be great.

thanks

I had a very similar problem - had a datalist where each itemtemplate contained an updatepanel.Inside the itemtemplate was a control called "selDriver", and on the main page there was also a control called "selDriver" - this was never a problem until the updatepanel was added in, and then it broke the compilation.I had to change the control's name in the main page to something different (which in retrospect I should have done anyway!) so I suspect you are experiencing something similar.Good luck!

Try to do with different name for both controls