473,329 Members | 1,290 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,329 software developers and data experts.

Datagrid with dynamic columns and updatepanel - ajax.net

An updatepanel contains a datagrid, this datagrid has columns generated by code-behind: some columns should have async postback, others should have sync postback.

Here a sample to reproduce the behaviour: it's a webform with some VB code-behind, you shoud create a new AJAX-enabled application and past the following code.

(DEFAULT.ASPX)
[HTML]
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:sqldatasource id="SqlDataSource1" runat="server"
connectionstring="Server=s-netbe1;UID=netbe;PWD=netbe;Database=versione2-tmp;"
selectcommand="SELECT * FROM wtesti"
></asp:sqldatasource>
<div>
-<%=DateTime.Now%>-
<asp:updatepanel id="upddgd" runat="server">
<contenttemplate>
<asp:label id="labprova" runat="server"></asp:label>
<asp:datagrid id="dgdprova" runat=server datasourceid="sqldatasource1" autogeneratecolumns="false">
</asp:datagrid>
</contenttemplate>
</asp:updatepanel>
</div>
</form>
</body>
</html>

[/HTML]

(DEFAULT.ASPX.VB)
Expand|Select|Wrap|Line Numbers
  1. Partial Class _Default
  2.     Inherits System.Web.UI.Page
  3.  
  4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.         Dim dat As New BoundColumn
  6.         dat.DataField = "titolo1"
  7.         dgdprova.Columns.Add(dat)
  8.         Dim ajx As New ButtonColumn
  9.         ajx.CommandName = "ajax"
  10.         ajx.Text = "Ajax"
  11.         dgdprova.Columns.Add(ajx)
  12.         Dim pst As New ButtonColumn
  13.         pst.CommandName = "post"
  14.         pst.Text = "Postback"
  15.         dgdprova.Columns.Add(pst)
  16.         Me.dgdprova.DataBind()
  17.     End Sub
  18.     Protected Sub dgdprova_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgdprova.ItemCommand
  19.         Me.labprova.Text = "PB " + Now.ToLongTimeString
  20.     End Sub
  21.  
  22.     Protected Sub dgdprova_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgdprova.ItemDataBound
  23.         Select Case e.Item.ItemType
  24.             Case ListItemType.AlternatingItem, ListItemType.Item
  25.                 Dim cella As New TableCell
  26.                 cella = e.Item.Cells(2)
  27.                 Dim tr As New PostBackTrigger
  28.                 tr.ControlID = cella.Controls(0).ClientID
  29.                 Me.upddgd.Triggers.Add(tr)
  30.         End Select
  31.     End Sub
  32.  
  33. End Class
  34.  
When I run the project it give the following error:


A control with ID 'dgdprova_ctl02_ctl01' could not be found for the trigger in UpdatePanel 'upddgd'.

[InvalidOperationException: A control with ID 'dgdprova_ctl02_ctl01' could not be found for the trigger in UpdatePanel 'upddgd'.]

System.Web.UI.UpdatePanelControlTrigger.FindTarget Control(Boolean searchNamingContainers) +315
System.Web.UI.PostBackTrigger.Initialize() +12
System.Web.UI.UpdatePanelTriggerCollection.Initial ize() +65
System.Web.UI.UpdatePanel.Initialize() +37
System.Web.UI.UpdatePanel.OnLoad(EventArgs e) +51
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436

Any help would be appreciated!
Nov 23 '07 #1
1 8187
I finally found a solution!! I must use the RegisterPostBackControl method of the ScriptManager control of the page

Expand|Select|Wrap|Line Numbers
  1.     Protected Sub dgdprova_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgdprova.ItemDataBound
  2.         Select Case e.Item.ItemType
  3.             Case ListItemType.AlternatingItem, ListItemType.Item
  4.                 ScriptManager1.RegisterPostBackControl(e.Item.Cells(2).Controls(0))
  5.         End Select
  6.     End Sub


Now the second buttoncolumn will post synchronously
Nov 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: lu | last post by:
I have a page with datagrid (for viewing, delete,edit,update) and text fields with button to add info to database. When user comes to page the datagrid selects info from database, binds in...
7
by: smithb1028 | last post by:
I have a simple DataGrid and trying to get paging to work. I orginially want to use this in an AJAX UpdatePanel, but I moved it out of it until I get it to work. This is the DataGrid in the...
2
by: brett | last post by:
I have an AJAX updatepanel in an aspx page. Inside the updatepanel is a placeholder control, which loads various ascx files. This all works fine. One of the ascx files also has an updatepanel in...
23
by: rsdev | last post by:
Hi, I have read hundreds of post regarding this issue, but none have an answer for my situation. So hopefully somebody here can help! I have a gridview in an updatepanel (AJAX control toolkit)...
5
daJunkCollector
by: daJunkCollector | last post by:
What I am doing here should be obvious. I have a datagrid that displays data properly. I want to create a linkbutton within each row of the datagrid that toggles a label control in the same row...
1
by: =?Utf-8?B?T2xlZw==?= | last post by:
Hi, I'm wondering if anybody using ajax extensions where UpdatePanel tag is used in addition to existing ajax implementation where UpdatePanel wasn't used yet. So, there is already a web project...
1
by: Theo | last post by:
I've got a bit of an issue that I'm trying to work out. I have the page structure described in the subject, and performance seems to have taken a nose dive, from perfectly acceptable at 8...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
12
by: ive1122 | last post by:
Hi guys, I am looking into create a dynamic survey as posted in Get User Input From Dynamic Controls but with some different environment Below is what i am trying to do: First when the user...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.