473,378 Members | 1,471 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,378 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.

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:sqldatasource id="SqlDataSource1" runat="server"
selectcommand="SELECT * FROM wtesti"
<asp:updatepanel id="upddgd" runat="server">
<asp:label id="labprova" runat="server"></asp:label>
<asp:datagrid id="dgdprova" runat=server datasourceid="sqldatasource1" autogeneratecolumns="false">


Expand|Select|Wrap|Line Numbers
  1. Partial Class _Default
  2.     Inherits System.Web.UI.Page
  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
  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
  33. End Class
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 8189
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

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...
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...
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...
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)...
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...
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...
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...
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...
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...
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...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.