Showing posts with label asp. Show all posts
Showing posts with label asp. Show all posts

Wednesday, March 28, 2012

Dynamic association between UpdatePanel and UpdateProgress not working

Hi,

I haven't really used the ASP.NET AJAX framework before and I'm trying to get this to work without any luck. On my page is a repeater control and in its itemtemplate I generate an UpdatePanel and an UpdateProgress control (and a couple of other items) along with a LinkButton. The UpdatePanel has another repeater inside it. The idea is when I click on of the LinkButtons, it binds a datasource to the innermost repeater and refreshes the associated UpdatePanel (the panel is set to Conditional updatemode). It all works well but the associated UpdateProgress doesn't show, ever.

I've tried declarative setting the AssociatedUpdatePanelID in my ASP.NET code and I've tried to set it programatically in the ItemDataBound property of the outermost repeater (I've tried setting it to ID, ClientID and UniqueID) with no luck. If I leave the AssociatedUpdatePanelID untouched it sort of work but the problem is that ALL UpdateProgress controlls are displayed when a LinkButton is pressed.

The following experimentation code is the one I've been trying to make it work
 <asp:scriptmanager id="ScriptManager1" runat="server"> </asp:scriptmanager> <asp:repeater id="rptAlternatives" runat="server" onitemcreated="rptAlternatives_ItemCreated" onitemdatabound="rptAlternatives_ItemDataBound"> <itemtemplate> <div style="border: 1px solid #000; width: 300px; height: 100px; margin: 10px 0 10px 0;"> <asp:linkbutton id="lnkToggleSementPanel" runat="server" text="Toggle segments"></asp:linkbutton> <asp:updateprogress id="progress" runat="server" AssociatedUpdatePanelID="updSegmentPanel"> <ProgressTemplate> Loading... </ProgressTemplate> </asp:updateprogress> <asp:updatepanel id="updSegmentPanel" runat="server" updatemode="Conditional"> <contenttemplate> <asp:repeater id="rptSegments" runat="server"> <headertemplate> <div style="background-color: red; width: 100%;"> </headertemplate> <itemtemplate><%# Container.DataItem%> </itemtemplate> <footertemplate> </div> </footertemplate> </asp:repeater> </contenttemplate> </asp:updatepanel> </div> </itemtemplate> </asp:repeater>

using System;
using System.Collections.Generic;
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 partialclass _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<int> items =new List<int>();
for (int i = 0; i < 5; i++)
items.Add(i);

this.rptAlternatives.DataSource = items;
this.rptAlternatives.DataBind();
}
}
protected void rptAlternatives_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
LinkButton lnkToggleSementPanel = e.Item.FindControl("lnkToggleSementPanel")as LinkButton;
if (lnkToggleSementPanel !=null)
{
lnkToggleSementPanel.Click +=new EventHandler(lnkToggleSementPanel_Click);
lnkToggleSementPanel.CommandArgument = e.Item.ItemIndex.ToString();
this.ScriptManager1.RegisterAsyncPostBackControl(lnkToggleSementPanel);
}
}
}

protected void rptAlternatives_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
UpdatePanel updSegmentPanel = e.Item.FindControl("updSegmentPanel")as UpdatePanel;
if (updSegmentPanel !=null)
{
UpdateProgress progress = e.Item.FindControl("progress")as UpdateProgress;
if (progress !=null)
{
progress.DisplayAfter = 0;

// NON OF THESE WORK!
//progress.AssociatedUpdatePanelID = updSegmentPanel.ClientID;
//progress.AssociatedUpdatePanelID = updSegmentPanel.UniqueID;
//progress.AssociatedUpdatePanelID = updSegmentPanel.ID;
}
}
}
}

void lnkToggleSementPanel_Click(object sender, EventArgs e)
{
LinkButton lnkToggleSementPanel = senderas LinkButton;
if (lnkToggleSementPanel !=null)
{
Control parentControl =
lnkToggleSementPanel.Parent;
UpdatePanel updSegmentPanel = parentControl.FindControl("updSegmentPanel")as UpdatePanel;

if (updSegmentPanel !=null)
{
Repeater rptSegments = updSegmentPanel.FindControl("rptSegments")as Repeater;
if( rptSegments !=null )
{
List<int> items =new List<int>();
for (int i = 0; i <= Convert.ToInt32(lnkToggleSementPanel.CommandArgument); i++)
items.Add(i);

rptSegments.DataSource = items;
rptSegments.DataBind();
updSegmentPanel.Update();

// Delay added for debugging
System.Threading.Thread.Sleep(1000);
}
}
}


}
}

Another thing that I've found strange is that if I move the assigning of the AssociatedUpdatePanelID property FROM ItemDataBound TO ItemCreated it all stops working and if you check the generated control ID's they've not been given proper IDs, i.e the NamingContainer stops working

No takers on this one? It appears Im just missing one piece of the puzzle but I can't figure out which oneSad


Hi,

Here is a working sample:

<%@. Page Language="C#" %><%@. Import Namespace="System.Collections.Generic" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { List<int> items = new List<int>(); for (int i = 0; i < 5; i++) items.Add(i); this.rptAlternatives.DataSource = items; this.rptAlternatives.DataBind(); } } protected void rptAlternatives_ItemCreated(object sender, RepeaterItemEventArgs e) { //if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) //{ // LinkButton lnkToggleSementPanel = e.Item.FindControl("lnkToggleSementPanel") as LinkButton; // if (lnkToggleSementPanel != null) // { // lnkToggleSementPanel.Click += new EventHandler(lnkToggleSementPanel_Click); // lnkToggleSementPanel.CommandArgument = e.Item.ItemIndex.ToString(); // this.ScriptManager1.RegisterAsyncPostBackControl(lnkToggleSementPanel); // } //} } protected void rptAlternatives_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { UpdatePanel updSegmentPanel = e.Item.FindControl("updSegmentPanel") as UpdatePanel; if (updSegmentPanel != null) { UpdateProgress progress = e.Item.FindControl("progress") as UpdateProgress; if (progress != null) { progress.DisplayAfter = 0; } } } } protected void rptAlternatives_ItemCommand(object source, RepeaterCommandEventArgs e) { LinkButton lnkToggleSementPanel = e.Item.FindControl("lnkToggleSementPanel") as LinkButton; if (lnkToggleSementPanel != null) { Control parentControl = lnkToggleSementPanel.Parent; UpdatePanel updSegmentPanel = parentControl.FindControl("updSegmentPanel") as UpdatePanel; if (updSegmentPanel != null) { Repeater rptSegments = updSegmentPanel.FindControl("rptSegments") as Repeater; if (rptSegments != null) { List<int> items = new List<int>(); for (int i = 0; i <= e.Item.ItemIndex; i++) items.Add(i); rptSegments.DataSource = items; rptSegments.DataBind(); updSegmentPanel.Update(); // Delay added for debugging System.Threading.Thread.Sleep(2000); } } } }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="ScriptManager1" runat="server"> </asp:scriptmanager> <asp:repeater id="rptAlternatives" runat="server" onitemcreated="rptAlternatives_ItemCreated" onitemdatabound="rptAlternatives_ItemDataBound" OnItemCommand="rptAlternatives_ItemCommand"> <itemtemplate> <div style="border: 1px solid #000; width: 300px; height: 100px; margin: 10px 0 10px 0;"> <asp:updatepanel id="updSegmentPanel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true"> <contenttemplate> <asp:linkbutton id="lnkToggleSementPanel" runat="server" text="Toggle segments"></asp:linkbutton> <asp:repeater id="rptSegments" runat="server"> <headertemplate> <div style="background-color: red; width: 100%;"> </headertemplate> <itemtemplate><%# Container.DataItem%> </itemtemplate> <footertemplate> </div> </footertemplate> </asp:repeater> </contenttemplate> <Triggers> </Triggers> </asp:updatepanel> <asp:updateprogress id="progress" runat="server" AssociatedUpdatePanelID="updSegmentPanel"> <ProgressTemplate> Loading... </ProgressTemplate> </asp:updateprogress> </div> </itemtemplate> </asp:repeater> </div> </form></body></html>

Please try it and compare with your own code.

Monday, March 26, 2012

Dynamic Accordion with Paging

hi there; using asp.net 2.0 (vb) i've just created a page that, in the page load event, retreives a number of records from the database.

as each record is read into a dataset, a new accordon panel is created. the panel header displays the fldName and the panel content displays the fldContent from the table.

this all works great. the issue i'm having is that it currently displays all the records (approx 200) and i only want 10 records displayed at a time.

my question is, is there somehow a way to implement paging? i found the following article:

http://rolf-cerff.de/blogs/dotnet/archive/2007/03/08/ajax-control-toolkit-paging-with-databound-accordion-control.aspx

but i'm not familiar enough with C# to understand.

also, any idea if paging for the accordion is in the works?

thanks all.

You can use a paged data source...

Basically, create a datatable from your recordset, and then...
Dim pds As New PagedDataSource
pds.DataSource = (whatever then dataset is called).Tables(0).DefaultView
pds.AllowPaging = True
pds.PageSize = 10
pds.CurrentPageIndex = curpage (passed into the databind sub, optional value that = 0 at first)
CurrentPage (see below) = pds.CurrentPageIndex + 1

What I do is to create a viewstate item called CurrentPage to keep track of the pages...
Public Property CurrentPage() As Integer
Get
Dim o As Object = Me.ViewState.Item("_CurrentPage")
If o Is Nothing Then
Return 0
Else
Return o
End If
End Get
Set(ByVal value As Integer)
Me.ViewState.Item("_CurrentPage") = value
End Set
End Property

You can then have linkbuttons to guide through pages... Just rebind using your sub and pass in CurrentPage as the curpage to advance or CurrentPage - 1 to go back.

Dynacly add scriptmanager when needed?

Hi,

I'm trying to create a Web User Control that uses asp.net Ajax. I'd like it to find out if a scriptmanager already exists in the page and, if not, add ti dynamically. Would such a thing be possible?


Thanks in advance for any help.


Regards,

Stefan

Yes its possible, you can check if ScriptManager is registered. FindControl(); or you can added it in the Master Page

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

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


Thanks for your quick reply. But how would I use FindControl if I don't know what the name of the scriptmanager would be?

I'm thinking of a situation where my control gets used in combination with other ajax controls, or gets used multpile times on a form. (Actually, my control would be a DotNetNuke module)

Any ideas?


If you didn't change it ScriptManager1


I know, but the hard thing is, that all controls get added to the page dynamically by DotNetNuke. This means I'm pretty sure the name won't be ScriptManager1...

So if there's no other way than to use findcontrol, the only option would be to add the ScripManager to the page itself somehow.


Thanks for your help.



hello.

you can get a reference to the ScriptManager control by using the static GetCurret method. If there's already a ScriptManager on the page, you will get a non null value.

I've put together an example ofUsing Control Adapters to automatically attach AJAX Extenders to ASP.NET Controls, which isn't exactly what you want, but there is code for walking through the controls on a page to see if there is already a ScriptManager or ScriptManagerProxy ...

http://damianblog.com/2006/11/16/adapters-and-extenders/

Damian


hello.

hum...why are you going through a cicle to get the scriptmanager control?


Because I'm doing it from an HttpModule ... and also because I didn't know of the static method :-)

Not sure if it will work in the module though ... will have a go.

Damian


hello.

well, i guess it might not work if you haven't instantiated the master page (which is easily solved by just "touching" the property)


Hi again, it's been a while since I had time to figure this thing out, but your answers look promising. Thanks a lot so far.

dropshadowextender visible when its targetcontrol is not

Hi

I have read thsi post which addresses this problem

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

I have downloaded the latest version of the toolkit and my dropshadowextender is visible when the control it's shadowing is not visible.

How can i modify the javsacript in DropShadowBehavior.js in my current dll. Presumably its embedded.

Thanks very much

andrea

Hi Andrea,

You can just edit the *.js files. You have torebuild the project for the changes to take effect though.

Thanks,
Ted
The fix mentioned in the above thread is known to work under at least some circumstances. Could you please post a simple sample demonstrating how it doesn't work in your scenario? That'll help us make a fix. Thanks.
thanks very much

DropShadowExtender and target panel separate when window is resized

So here's what's up.

I've got a horizontally scrolling asp panel.

In the panel is a datalist which repeats horizontally.

I have a web user control set as the item template. The user control makes use of the DropShadowExtender.

It works beautifully, until the window is resized, then the shadows and user controls part their ways.

Any ideas?

hello?

DropShadowExtender and asp .net 2.0 Menu Control

Hi, i'm having a problem using DropShadowExtender, when i use it in a panel bellow my menu (menu displaying items in hotizontal with children), the children menu items, appear behind the panel witch the DropShadowExtender is bounded.

Has anyone expererienced this? If so is there a simple solution to it?

I've tried to change several properties of the div where my menu is inserted, and did'nt work.

Thanks.

hi joao_matos,

Could you provide some sample code that shows what's going wrong? I'm not quite following your description.

Thanks,
Ted

Saturday, March 24, 2012

Dropshadow too low

I am have a problem with the dropshadow extender placing the shadow too low on the page. I have a series of asp panels on a page that are targets of dropshadow extenders, for some reason all of the shadow are being postioned too low on the page. It seem that the top shadow is is getting a sytle element with a top value that is placing it too low on the page, and then all of the other dropshadow extender panels are offset by the same value.

Can anyone shed some light as to how the dropshadow extender determines its top position? I assmed that I would be with regard to the posotion of the target panel, but that doesn't seem to be the case here.

Thanks.

Any help welcome!

Hi Audley9,

This kind of issues is usually caused by the css settings. Here is my sample that you can reference to. Please compare it with yours.

<%@. Page Language="C#" %><%@. 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 id="Head1" runat="server"> <title>Untitled Page</title> <style type="text/css">.overall { left: 10px; top: 10px; ; height: 500px; background-color: Silver; } .above { position: absolute; margin-left: 50px; margin-top: 50px; z-index: 2; } .aboveinside { width:300px; background-color:#5377A9; color:white; font-weight:bold; } .below { margin-top: 10px; left: 0px; width: 300px; height: 200px; z-index: 1; background-color: Blue; } </style></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div class="overall"> <asp:Panel ID="above" runat="server" CssClass="aboveinside"> <div style="padding:10px"> Here's some text in a box. </div> </asp:Panel> <cc1:DropShadowExtender ID="DropShadowExtender1" runat="server" TargetControlID="above" Width="5" Opacity=".5" Rounded="true" TrackPosition="true" Radius="6"> </cc1:DropShadowExtender> <div class="below">This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... This is some text underneath... </div> </div> </form></body></html>

I hope this help.

Best regards,

Jonathan


Thnaks for Answering!

I had solved this issue already but forgot to come back to this post. Whit my situation, I had a series of nested "Div' Tags that had "Postion: relative", set to the divs. I was trying to acomplish a rather complex layout using Css, which I was not able to acomplish (there were other issue besides this one), so I have had to intermingle css with table layout.

Thanks for the help!

DropdownList Update

Hi,

I have modified the sample program for Data Demo. I've used ASP.NET AJAX....I have a dropdownlist and a gridview inside an updatepanel. Also, im connected thru a objectdatasource. the dropdownlist gets value from objectdatasource1. The value comes from a distinct state from the author table while the gridview is connected to objectdatasource2. The value for objectdatasource2 comes from auther table where state = to the dropdownlist selected value.

Now what i want to achieve is that if i edit the state in the gridview my dropdownlist will be automacatically refresh. I tried adding <asp:AsyncPostBackTriggerControlID="GridView1"EventName="SelectedIndexChanged"/> to the updatepanel. I was able to save the changes but the dropdownlist doesnt.

Thanks

2lits

When both the controls that cause a refresh to the updatepanel are inside it, you can use the ChildrenAsTriggers property of the UpdatePanel. Set it to True, and your Dropdownlist should be re-binding.

Thanks


The ChildrenAsTriggers was already set to true but still my dropdownlist is not re-binding...any other thoughts? thanks!


Is your updateMode on conditional basis?

Thanks


it was set to always.

Thanks


I'd say step one is to remove the UpdatePanel and see if this is working in regular postback mode. If it is, then we need to figure out what's going wrong with your UpdatePanels.

I'd want to see some code at that point... is there just one UpdatePanel on the page? Is the GridView inside it? Is the DropDownList?


Yes There is only one Update Panel. The Gridview , dropdownlist, and the sources are inside it.

here's my code :

<formid="form1"runat="server"><asp:ScriptManagerID="ScriptManager1"runat="server"/> <divtitle="My First AJAX-Enabled Data Driven Page"><asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="Conditional"><ContentTemplate> <asp:DropDownListID="DropDownList1"runat="server"DataSourceID="ObjectDataSource1"DataTextField="State"DataValueField="State"AutoPostBack=True></asp:DropDownList><asp:GridViewID="GridView1"runat="server"AllowPaging="True"AutoGenerateColumns="False"DataSourceID="ObjectDataSource2"AllowSorting="True"DataKeyNames="AuthorID"><Columns><asp:CommandFieldShowEditButton="True"ShowSelectButton="True"/><asp:BoundFieldDataField="AuthorID"HeaderText="AuthorID"InsertVisible="False"ReadOnly="True"SortExpression="AuthorID"/><asp:BoundFieldDataField="FirstName"HeaderText="FirstName"SortExpression="FirstName"/><asp:BoundFieldDataField="LastName"HeaderText="LastName"SortExpression="LastName"/><asp:BoundFieldDataField="City"HeaderText="City"SortExpression="City"/><asp:BoundFieldDataField="State"HeaderText="State"SortExpression="State"/><asp:BoundFieldDataField="Zip"HeaderText="Zip"SortExpression="Zip"/><asp:BoundFieldDataField="Phone"HeaderText="Phone"SortExpression="Phone"/></Columns></asp:GridView><br/> <asp:ObjectDataSourceID="ObjectDataSource2"runat="server"OldValuesParameterFormatString="{0}"SelectMethod="GetData"TypeName="DataSet2TableAdapters.SelectAuthorsTableAdapter"UpdateMethod="Update"><SelectParameters><asp:ControlParameterControlID="DropDownList1"Name="State"PropertyName="SelectedValue"Type="String"/></SelectParameters><UpdateParameters><asp:ParameterName="AuthorID"Type="Int32"/><asp:ParameterName="FirstName"Type="String"/><asp:ParameterName="LastName"Type="String"/><asp:ParameterName="City"Type="String"/><asp:ParameterName="State"Type="String"/><asp:ParameterName="Zip"Type="String"/><asp:ParameterName="Phone"Type="String"/></UpdateParameters></asp:ObjectDataSource><asp:ObjectDataSourceID="ObjectDataSource1"runat="server"OldValuesParameterFormatString="original_{0}"SelectMethod="GetDataState"TypeName="DataSet2TableAdapters.StateListTableAdapter"></asp:ObjectDataSource><br/></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="SelectedIndexChanged"/><asp:AsyncPostBackTriggerControlID="GridView1"EventName="RowUpdated"/></Triggers></asp:UpdatePanel> </div></form>
The updatemode is set to always. I just test it to conditional.

The updatemode is set to always. I just test it to conditional.

Thanks


And what's supposed to happen to the DropDownList when you edit the GridView?

Did you try removing the UpdatePanel? I have a feeling this isn't working with regular postbacks either and doesn't really have to do with AJAX, since your UpdatePanel code looks correct.


I should be able to see the updates in the state. example if I change the state from MI to NW upon save i should be able to see NW added in the dropdownlist. It is working on the regular postback...

Steve Marx:

I have a feeling this isn't working with regular postbacks either and doesn't really have to do with AJAX, since your UpdatePanel code looks correct.

This is to do with AJAX. When the DropDownList is binded declaratively, the list wont get refreshed on the triggers of the updatepanel. You need to explicitly bind the dropdownlist in the events specified on the updatepanel. But if have you had used the same ObjectSource for both the GridView and DropDownList, then sure the list gets updated.

Since the OP is working on the same database table, one ObjectDataSource is enough and when the GridView UpdateCommand is called, the data for the DropDownList is pulled again.

Thanks


e_screw, I don't quite understand... the databinding should work exactly the same way in a regular postback and an async postback. I'm still having trouble figuring out how this can work without the UpdatePanel but fail with it.

Certainly the DropDownList has to be bound again in the event handler, but what does that have to do with AJAX?


yes..thats also my understanding. How does the updatepanel rebind the data?

Thanks so much!


Steve Marx:

... the databinding should work exactly the same way in a regular postback and an async postback. I'm still having trouble figuring out how this can work without the UpdatePanel but fail with it. Certainly the DropDownList has to be bound again in the event handler, but what does that have to do with AJAX?

I am not sure though (still learning AJAX), the DataBinding of the controls (set declaratively using DataSourceID) will be started before the PreRender event of the page and not sure if the necessary client-scripts for that will be injected into the page by AJAX. I have checked with a different ObjectDataSource (each for Dropdownlist and GridView), and there was no client-script generated for the DropDownList unless there was explicit binding. When you are using the same ObjectDataSource for both the controls, there was client-script inject for both even if there was no explicit binding.

Thanks

Wednesday, March 21, 2012

DropDownList Events

Hi There,

I started playing ASP.NET AJAX some months ago as part of a Universiy project. I've recently come back to it and have made most of the changes I think I need to make to use the new ASP.NET AJAX beta (I was previously using the Atlas CTP). However, I have a problem with dwopdownlist event names.

I have a basic application that has a drop down list and a repeater. The dropdownlist is bound to the one side of a DB relationship and the repeater is bound to the many. All works fine in terms of displaying the controls on the page but I can't get the repeater control list to change based on the valyue selected in the dropdown list. The last few lines of code within <asp:updatePanel/> are as follows:

<Triggers>

<asp:AsyncPostBackTriggerControlID="DropDownList1"EventName="OnSelectedIndexChange"/></Triggers>

The problem is the EventName attribute not being recognised. I have searched evrywhere for a comprehensive list of Dropdownlist evcent names but I can't find anything. What I have found hasn't worked.

Am I missibg something else or is it simply a case of the dropdownlist event name being incorrect.

Thanks in advance for your help.

Kind Regards

Mike

i was the same question with you before.

try using EventName = "SelectedIndexChanged"