HighTechTalks DotNet Forums  

IPostBackDataHandler not working properly with DataGrid

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss IPostBackDataHandler not working properly with DataGrid in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
buzlite@sympatico.ca
 
Posts: n/a

Default IPostBackDataHandler not working properly with DataGrid - 08-11-2006 , 05:50 PM






Hello All,


I've posted this in
microsoft.public.dotnet.framework.aspnet.datagridc ontrol but got not
reply so I'll try my luck here.

Any help would be greatly appreciated.
Thanks



I am having some difficulties with a user control implementing
IPostBackDataHandler when it is placed inside a datagrid.

I have created a user control (MyUserControl.ascx) containing 1 TextBox
that implements the IPostBackDataHandler.
I have also created a form (WebForm1.aspx) that contains 1 datagrid of
which the datagrid contains the above user control as specified in its
template.

The purpose is to dynamically create one MyUserControl for each item in
the datasource for display and editing.

When the program is run and text is entered into MyUserControl's
textbox, the LoadPostData() of MyUserControl.ascx is called as
expected. But even though LoadPostData() returns true the
corresponding RaisePostDataChangedEvent() is not called.


Note: if I were to simply include the MyUserControl.ascx in
WebForm1.aspx, then both LoadPostData() and RaisePostDataChangedEvent()
of MyUserControl.ascx are called as expected.

Would someone give me some insight as to why this is not working ? Am
I missing a step somewhere ?



Attached is the bare essential code snippets to reproduce the problem.


MyUserControl.ascx
-----------------------------------------------------
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="MyUserControl.ascx.cs" Inherits="test.MyUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>


MyUserControl.ascx.cs
-----------------------------------------------------
public class MyUserControl : System.Web.UI.UserControl,
IPostBackDataHandler, INamingContainer
{
protected System.Web.UI.WebControls.TextBox TextBox1;


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


public virtual bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
return true;
}

public virtual void RaisePostDataChangedEvent()
{
}

private void Page_Load(object sender, System.EventArgs e)
{
}
}



WebForm1.aspx
------------------------------------------------------
<%@ Register TagPrefix="f4c" TagName="MyUserControl"
Src="MyUserControl.ascx" %>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="test.WebForm1" %>
....
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgListing" runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<f4c:MyUserControl id="MyUserControl1"
runat="server"></f4c:MyUserControl>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>


WebForm1.aspx.cs
------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{

....
private void Page_Load(object sender, System.EventArgs e)
{
//setup handlers
this.Button1.Click += new System.EventHandler(this.Button1_Click);

//setup datagrid
dgListing.DataSource = this.CreateDataSource();
dgListing.DataBind();
}

private void Button1_Click(object sender, System.EventArgs e)
{
}

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("SomeColumn", typeof(Int32)));

for (int i = 0; i < 2; i++)
{
dr = dt.NewRow();
dr[0] = i;
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}
}


Reply With Quote
  #2  
Old   
Gaurav Vaish \(www.EduJini.IN\)
 
Posts: n/a

Default Re: IPostBackDataHandler not working properly with DataGrid - 08-11-2006 , 10:28 PM






Quote:
The purpose is to dynamically create one MyUserControl for each item in
the datasource for display and editing.
How and where are you adding it?

The best place is CreateChildControls() method.


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------




Reply With Quote
  #3  
Old   
buzlite@sympatico.ca
 
Posts: n/a

Default Re: IPostBackDataHandler not working properly with DataGrid - 08-12-2006 , 08:55 AM



The user control is added inside the WebForm1.aspx file inside the
column template of the datagrid control

Thanks


Gaurav Vaish (www.EduJini.IN) wrote:
Quote:
The purpose is to dynamically create one MyUserControl for each item in
the datasource for display and editing.

How and where are you adding it?

The best place is CreateChildControls() method.


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


Reply With Quote
  #4  
Old   
buzlite@sympatico.ca
 
Posts: n/a

Default Re: IPostBackDataHandler not working properly with DataGrid - 08-14-2006 , 09:55 AM



Hello All,
Any help would be appreciated.
Thanks



buzlite (AT) sympatico (DOT) ca wrote:
Quote:
Hello All,


I've posted this in
microsoft.public.dotnet.framework.aspnet.datagridc ontrol but got not
reply so I'll try my luck here.

Any help would be greatly appreciated.
Thanks



I am having some difficulties with a user control implementing
IPostBackDataHandler when it is placed inside a datagrid.

I have created a user control (MyUserControl.ascx) containing 1 TextBox
that implements the IPostBackDataHandler.
I have also created a form (WebForm1.aspx) that contains 1 datagrid of
which the datagrid contains the above user control as specified in its
template.

The purpose is to dynamically create one MyUserControl for each item in
the datasource for display and editing.

When the program is run and text is entered into MyUserControl's
textbox, the LoadPostData() of MyUserControl.ascx is called as
expected. But even though LoadPostData() returns true the
corresponding RaisePostDataChangedEvent() is not called.


Note: if I were to simply include the MyUserControl.ascx in
WebForm1.aspx, then both LoadPostData() and RaisePostDataChangedEvent()
of MyUserControl.ascx are called as expected.

Would someone give me some insight as to why this is not working ? Am
I missing a step somewhere ?



Attached is the bare essential code snippets to reproduce the problem.


MyUserControl.ascx
-----------------------------------------------------
%@ Control Language="c#" AutoEventWireup="false"
Codebehind="MyUserControl.ascx.cs" Inherits="test.MyUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%
asp:TextBox id="TextBox1" runat="server"></asp:TextBox


MyUserControl.ascx.cs
-----------------------------------------------------
public class MyUserControl : System.Web.UI.UserControl,
IPostBackDataHandler, INamingContainer
{
protected System.Web.UI.WebControls.TextBox TextBox1;


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
}

/// <summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


public virtual bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
return true;
}

public virtual void RaisePostDataChangedEvent()
{
}

private void Page_Load(object sender, System.EventArgs e)
{
}
}



WebForm1.aspx
------------------------------------------------------
%@ Register TagPrefix="f4c" TagName="MyUserControl"
Src="MyUserControl.ascx" %
%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="test.WebForm1" %
...
form id="Form1" method="post" runat="server"
asp:datagrid id="dgListing" runat="server"
AutoGenerateColumns="False"
Columns
asp:TemplateColumn
ItemTemplate
f4c:MyUserControl id="MyUserControl1"
runat="server"></f4c:MyUserControl
/ItemTemplate
/asp:TemplateColumn
/Columns
/asp:datagrid
asp:Button id="Button1" runat="server" Text="Button"></asp:Button
/form


WebForm1.aspx.cs
------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{

...
private void Page_Load(object sender, System.EventArgs e)
{
//setup handlers
this.Button1.Click += new System.EventHandler(this.Button1_Click);

//setup datagrid
dgListing.DataSource = this.CreateDataSource();
dgListing.DataBind();
}

private void Button1_Click(object sender, System.EventArgs e)
{
}

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("SomeColumn", typeof(Int32)));

for (int i = 0; i < 2; i++)
{
dr = dt.NewRow();
dr[0] = i;
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}
}


Reply With Quote
  #5  
Old   
Gaurav Vaish \(www.EduJini.IN\)
 
Posts: n/a

Default Re: IPostBackDataHandler not working properly with DataGrid - 08-14-2006 , 11:30 AM



Hi,

The only missing thing that will need to fill, as I think, is a simple
hidden field... so that it can be captured in LoadPostData.

btw, what happens if you blindly return 'true' in LoadPostData?


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


<buzlite (AT) sympatico (DOT) ca> wrote

Quote:
Hello All,
Any help would be appreciated.
Thanks



buzlite (AT) sympatico (DOT) ca wrote:
Hello All,


I've posted this in
microsoft.public.dotnet.framework.aspnet.datagridc ontrol but got not
reply so I'll try my luck here.

Any help would be greatly appreciated.
Thanks



I am having some difficulties with a user control implementing
IPostBackDataHandler when it is placed inside a datagrid.

I have created a user control (MyUserControl.ascx) containing 1 TextBox
that implements the IPostBackDataHandler.
I have also created a form (WebForm1.aspx) that contains 1 datagrid of
which the datagrid contains the above user control as specified in its
template.

The purpose is to dynamically create one MyUserControl for each item in
the datasource for display and editing.

When the program is run and text is entered into MyUserControl's
textbox, the LoadPostData() of MyUserControl.ascx is called as
expected. But even though LoadPostData() returns true the
corresponding RaisePostDataChangedEvent() is not called.


Note: if I were to simply include the MyUserControl.ascx in
WebForm1.aspx, then both LoadPostData() and RaisePostDataChangedEvent()
of MyUserControl.ascx are called as expected.

Would someone give me some insight as to why this is not working ? Am
I missing a step somewhere ?



Attached is the bare essential code snippets to reproduce the problem.


MyUserControl.ascx
-----------------------------------------------------
%@ Control Language="c#" AutoEventWireup="false"
Codebehind="MyUserControl.ascx.cs" Inherits="test.MyUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%
asp:TextBox id="TextBox1" runat="server"></asp:TextBox


MyUserControl.ascx.cs
-----------------------------------------------------
public class MyUserControl : System.Web.UI.UserControl,
IPostBackDataHandler, INamingContainer
{
protected System.Web.UI.WebControls.TextBox TextBox1;


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
}

/// <summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


public virtual bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
return true;
}

public virtual void RaisePostDataChangedEvent()
{
}

private void Page_Load(object sender, System.EventArgs e)
{
}
}



WebForm1.aspx
------------------------------------------------------
%@ Register TagPrefix="f4c" TagName="MyUserControl"
Src="MyUserControl.ascx" %
%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="test.WebForm1" %
...
form id="Form1" method="post" runat="server"
asp:datagrid id="dgListing" runat="server"
AutoGenerateColumns="False"
Columns
asp:TemplateColumn
ItemTemplate
f4c:MyUserControl id="MyUserControl1"
runat="server"></f4c:MyUserControl
/ItemTemplate
/asp:TemplateColumn
/Columns
/asp:datagrid
asp:Button id="Button1" runat="server" Text="Button"></asp:Button
/form


WebForm1.aspx.cs
------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{

...
private void Page_Load(object sender, System.EventArgs e)
{
//setup handlers
this.Button1.Click += new System.EventHandler(this.Button1_Click);

//setup datagrid
dgListing.DataSource = this.CreateDataSource();
dgListing.DataBind();
}

private void Button1_Click(object sender, System.EventArgs e)
{
}

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("SomeColumn", typeof(Int32)));

for (int i = 0; i < 2; i++)
{
dr = dt.NewRow();
dr[0] = i;
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}
}




Reply With Quote
  #6  
Old   
buzlite@sympatico.ca
 
Posts: n/a

Default Re: IPostBackDataHandler not working properly with DataGrid - 08-14-2006 , 04:46 PM



Hello Gaurav,

I do not know the reasoning for adding a hidden field and what purpose
that would accomplish.

Quote:
From the sample code attachments, when WebForm1.aspx is run and the
Datagrid generates MyUserControl user control, any text that is entered
in this user control TextBox would be properly posted back to the
server. This is true in that when MyUserControl.ascx.cs,
LoadPostData() is called, the data can be retrieved from the input
parameter of this method. So...this is working OK.

The problem is, when MyUserControl.ascx.cs, LoadPostData() returns a
value of 'true', RaisePostDataChangedEvent() is never invoked. In the
MyUserControl.ascx.cs code snippet, I hardcoded a return of 'true'.
Even then, RaisePostDataChangedEvent() is never invoked. This is the
main problem that I am experiencing.

Any insights ?

Thanks



Gaurav Vaish (www.EduJini.IN) wrote:
Quote:
Hi,

The only missing thing that will need to fill, as I think, is a simple
hidden field... so that it can be captured in LoadPostData.

btw, what happens if you blindly return 'true' in LoadPostData?


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


buzlite (AT) sympatico (DOT) ca> wrote in message
news:1155567351.199524.188830 (AT) m79g2000cwm (DOT) googlegroups.com...
Hello All,
Any help would be appreciated.
Thanks



buzlite (AT) sympatico (DOT) ca wrote:
Hello All,


I've posted this in
microsoft.public.dotnet.framework.aspnet.datagridc ontrol but got not
reply so I'll try my luck here.

Any help would be greatly appreciated.
Thanks



I am having some difficulties with a user control implementing
IPostBackDataHandler when it is placed inside a datagrid.

I have created a user control (MyUserControl.ascx) containing 1 TextBox
that implements the IPostBackDataHandler.
I have also created a form (WebForm1.aspx) that contains 1 datagrid of
which the datagrid contains the above user control as specified in its
template.

The purpose is to dynamically create one MyUserControl for each item in
the datasource for display and editing.

When the program is run and text is entered into MyUserControl's
textbox, the LoadPostData() of MyUserControl.ascx is called as
expected. But even though LoadPostData() returns true the
corresponding RaisePostDataChangedEvent() is not called.


Note: if I were to simply include the MyUserControl.ascx in
WebForm1.aspx, then both LoadPostData() and RaisePostDataChangedEvent()
of MyUserControl.ascx are called as expected.

Would someone give me some insight as to why this is not working ? Am
I missing a step somewhere ?



Attached is the bare essential code snippets to reproduce the problem.


MyUserControl.ascx
-----------------------------------------------------
%@ Control Language="c#" AutoEventWireup="false"
Codebehind="MyUserControl.ascx.cs" Inherits="test.MyUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%
asp:TextBox id="TextBox1" runat="server"></asp:TextBox


MyUserControl.ascx.cs
-----------------------------------------------------
public class MyUserControl : System.Web.UI.UserControl,
IPostBackDataHandler, INamingContainer
{
protected System.Web.UI.WebControls.TextBox TextBox1;


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
}

/// <summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


public virtual bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
return true;
}

public virtual void RaisePostDataChangedEvent()
{
}

private void Page_Load(object sender, System.EventArgs e)
{
}
}



WebForm1.aspx
------------------------------------------------------
%@ Register TagPrefix="f4c" TagName="MyUserControl"
Src="MyUserControl.ascx" %
%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="test.WebForm1" %
...
form id="Form1" method="post" runat="server"
asp:datagrid id="dgListing" runat="server"
AutoGenerateColumns="False"
Columns
asp:TemplateColumn
ItemTemplate
f4c:MyUserControl id="MyUserControl1"
runat="server"></f4c:MyUserControl
/ItemTemplate
/asp:TemplateColumn
/Columns
/asp:datagrid
asp:Button id="Button1" runat="server" Text="Button"></asp:Button
/form


WebForm1.aspx.cs
------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{

...
private void Page_Load(object sender, System.EventArgs e)
{
//setup handlers
this.Button1.Click += new System.EventHandler(this.Button1_Click);

//setup datagrid
dgListing.DataSource = this.CreateDataSource();
dgListing.DataBind();
}

private void Button1_Click(object sender, System.EventArgs e)
{
}

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("SomeColumn", typeof(Int32)));

for (int i = 0; i < 2; i++)
{
dr = dt.NewRow();
dr[0] = i;
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}
}



Reply With Quote
  #7  
Old   
Gaurav Vaish \(www.EduJini.IN\)
 
Posts: n/a

Default Re: IPostBackDataHandler not working properly with DataGrid - 08-14-2006 , 10:50 PM



Let me give it a shot by creating a dummy 'UserControl' on my own.

--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


<buzlite (AT) sympatico (DOT) ca> wrote

Quote:
Hello Gaurav,

I do not know the reasoning for adding a hidden field and what purpose
that would accomplish.

From the sample code attachments, when WebForm1.aspx is run and the
Datagrid generates MyUserControl user control, any text that is entered
in this user control TextBox would be properly posted back to the
server. This is true in that when MyUserControl.ascx.cs,
LoadPostData() is called, the data can be retrieved from the input
parameter of this method. So...this is working OK.

The problem is, when MyUserControl.ascx.cs, LoadPostData() returns a
value of 'true', RaisePostDataChangedEvent() is never invoked. In the
MyUserControl.ascx.cs code snippet, I hardcoded a return of 'true'.
Even then, RaisePostDataChangedEvent() is never invoked. This is the
main problem that I am experiencing.

Any insights ?

Thanks



Gaurav Vaish (www.EduJini.IN) wrote:
Hi,

The only missing thing that will need to fill, as I think, is a simple
hidden field... so that it can be captured in LoadPostData.

btw, what happens if you blindly return 'true' in LoadPostData?


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


buzlite (AT) sympatico (DOT) ca> wrote in message
news:1155567351.199524.188830 (AT) m79g2000cwm (DOT) googlegroups.com...
Hello All,
Any help would be appreciated.
Thanks



buzlite (AT) sympatico (DOT) ca wrote:
Hello All,


I've posted this in
microsoft.public.dotnet.framework.aspnet.datagridc ontrol but got not
reply so I'll try my luck here.

Any help would be greatly appreciated.
Thanks



I am having some difficulties with a user control implementing
IPostBackDataHandler when it is placed inside a datagrid.

I have created a user control (MyUserControl.ascx) containing 1
TextBox
that implements the IPostBackDataHandler.
I have also created a form (WebForm1.aspx) that contains 1 datagrid of
which the datagrid contains the above user control as specified in its
template.

The purpose is to dynamically create one MyUserControl for each item
in
the datasource for display and editing.

When the program is run and text is entered into MyUserControl's
textbox, the LoadPostData() of MyUserControl.ascx is called as
expected. But even though LoadPostData() returns true the
corresponding RaisePostDataChangedEvent() is not called.


Note: if I were to simply include the MyUserControl.ascx in
WebForm1.aspx, then both LoadPostData() and
RaisePostDataChangedEvent()
of MyUserControl.ascx are called as expected.

Would someone give me some insight as to why this is not working ? Am
I missing a step somewhere ?



Attached is the bare essential code snippets to reproduce the problem.


MyUserControl.ascx
-----------------------------------------------------
%@ Control Language="c#" AutoEventWireup="false"
Codebehind="MyUserControl.ascx.cs" Inherits="test.MyUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%
asp:TextBox id="TextBox1" runat="server"></asp:TextBox


MyUserControl.ascx.cs
-----------------------------------------------------
public class MyUserControl : System.Web.UI.UserControl,
IPostBackDataHandler, INamingContainer
{
protected System.Web.UI.WebControls.TextBox TextBox1;


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
}

/// <summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


public virtual bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
return true;
}

public virtual void RaisePostDataChangedEvent()
{
}

private void Page_Load(object sender, System.EventArgs e)
{
}
}



WebForm1.aspx
------------------------------------------------------
%@ Register TagPrefix="f4c" TagName="MyUserControl"
Src="MyUserControl.ascx" %
%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="test.WebForm1" %
...
form id="Form1" method="post" runat="server"
asp:datagrid id="dgListing" runat="server"
AutoGenerateColumns="False"
Columns
asp:TemplateColumn
ItemTemplate
f4c:MyUserControl id="MyUserControl1"
runat="server"></f4c:MyUserControl
/ItemTemplate
/asp:TemplateColumn
/Columns
/asp:datagrid
asp:Button id="Button1" runat="server" Text="Button"></asp:Button
/form


WebForm1.aspx.cs
------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{

...
private void Page_Load(object sender, System.EventArgs e)
{
//setup handlers
this.Button1.Click += new System.EventHandler(this.Button1_Click);

//setup datagrid
dgListing.DataSource = this.CreateDataSource();
dgListing.DataBind();
}

private void Button1_Click(object sender, System.EventArgs e)
{
}

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("SomeColumn", typeof(Int32)));

for (int i = 0; i < 2; i++)
{
dr = dt.NewRow();
dr[0] = i;
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}
}





Reply With Quote
  #8  
Old   
Gaurav Vaish \(www.EduJini.IN\)
 
Posts: n/a

Default Re: IPostBackDataHandler not working properly with DataGrid - 08-14-2006 , 11:39 PM



Problem solved.
btw, the hidden field would be required because of the following reason:

For each ClientID that appears in the form and the control corresponding to
the same, the IPostBackDataHandler methods would be called.
And for no else.

Here's a trick:

Add a hidden field during 'Render' to the output.

You may download the code (that I wrote) from the following URL:
http://www.edujini.in/samples/ASP.Net/2.0/DataHandlerControl.zip


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


"Gaurav Vaish (www.EduJini.IN)" <gaurav.vaish.nospam (AT) nospam (DOT) gmail.com> wrote
in message news:OOulE4BwGHA.1288 (AT) TK2MSFTNGP02 (DOT) phx.gbl...
Quote:
Let me give it a shot by creating a dummy 'UserControl' on my own.

--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


buzlite (AT) sympatico (DOT) ca> wrote in message
news:1155591996.737095.53890 (AT) b28g2000cwb (DOT) googlegroups.com...
Hello Gaurav,

I do not know the reasoning for adding a hidden field and what purpose
that would accomplish.

From the sample code attachments, when WebForm1.aspx is run and the
Datagrid generates MyUserControl user control, any text that is entered
in this user control TextBox would be properly posted back to the
server. This is true in that when MyUserControl.ascx.cs,
LoadPostData() is called, the data can be retrieved from the input
parameter of this method. So...this is working OK.

The problem is, when MyUserControl.ascx.cs, LoadPostData() returns a
value of 'true', RaisePostDataChangedEvent() is never invoked. In the
MyUserControl.ascx.cs code snippet, I hardcoded a return of 'true'.
Even then, RaisePostDataChangedEvent() is never invoked. This is the
main problem that I am experiencing.

Any insights ?

Thanks



Gaurav Vaish (www.EduJini.IN) wrote:
Hi,

The only missing thing that will need to fill, as I think, is a simple
hidden field... so that it can be captured in LoadPostData.

btw, what happens if you blindly return 'true' in LoadPostData?


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


buzlite (AT) sympatico (DOT) ca> wrote in message
news:1155567351.199524.188830 (AT) m79g2000cwm (DOT) googlegroups.com...
Hello All,
Any help would be appreciated.
Thanks



buzlite (AT) sympatico (DOT) ca wrote:
Hello All,


I've posted this in
microsoft.public.dotnet.framework.aspnet.datagridc ontrol but got not
reply so I'll try my luck here.

Any help would be greatly appreciated.
Thanks



I am having some difficulties with a user control implementing
IPostBackDataHandler when it is placed inside a datagrid.

I have created a user control (MyUserControl.ascx) containing 1
TextBox
that implements the IPostBackDataHandler.
I have also created a form (WebForm1.aspx) that contains 1 datagrid
of
which the datagrid contains the above user control as specified in
its
template.

The purpose is to dynamically create one MyUserControl for each item
in
the datasource for display and editing.

When the program is run and text is entered into MyUserControl's
textbox, the LoadPostData() of MyUserControl.ascx is called as
expected. But even though LoadPostData() returns true the
corresponding RaisePostDataChangedEvent() is not called.


Note: if I were to simply include the MyUserControl.ascx in
WebForm1.aspx, then both LoadPostData() and
RaisePostDataChangedEvent()
of MyUserControl.ascx are called as expected.

Would someone give me some insight as to why this is not working ?
Am
I missing a step somewhere ?



Attached is the bare essential code snippets to reproduce the
problem.


MyUserControl.ascx
-----------------------------------------------------
%@ Control Language="c#" AutoEventWireup="false"
Codebehind="MyUserControl.ascx.cs" Inherits="test.MyUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%
asp:TextBox id="TextBox1" runat="server"></asp:TextBox


MyUserControl.ascx.cs
-----------------------------------------------------
public class MyUserControl : System.Web.UI.UserControl,
IPostBackDataHandler, INamingContainer
{
protected System.Web.UI.WebControls.TextBox TextBox1;


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
}

/// <summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


public virtual bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
return true;
}

public virtual void RaisePostDataChangedEvent()
{
}

private void Page_Load(object sender, System.EventArgs e)
{
}
}



WebForm1.aspx
------------------------------------------------------
%@ Register TagPrefix="f4c" TagName="MyUserControl"
Src="MyUserControl.ascx" %
%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="test.WebForm1" %
...
form id="Form1" method="post" runat="server"
asp:datagrid id="dgListing" runat="server"
AutoGenerateColumns="False"
Columns
asp:TemplateColumn
ItemTemplate
f4c:MyUserControl id="MyUserControl1"
runat="server"></f4c:MyUserControl
/ItemTemplate
/asp:TemplateColumn
/Columns
/asp:datagrid
asp:Button id="Button1" runat="server" Text="Button"></asp:Button
/form


WebForm1.aspx.cs
------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{

...
private void Page_Load(object sender, System.EventArgs e)
{
//setup handlers
this.Button1.Click += new System.EventHandler(this.Button1_Click);

//setup datagrid
dgListing.DataSource = this.CreateDataSource();
dgListing.DataBind();
}

private void Button1_Click(object sender, System.EventArgs e)
{
}

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("SomeColumn", typeof(Int32)));

for (int i = 0; i < 2; i++)
{
dr = dt.NewRow();
dr[0] = i;
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}
}







Reply With Quote
  #9  
Old   
buzlite001@hotmail.com
 
Posts: n/a

Default Re: IPostBackDataHandler not working properly with DataGrid - 08-15-2006 , 02:54 PM



Hello Gaurav,

Thanks for you attempt but it was not answering the initial problem.

The initial problem was that the MyUserControl is embedded in a
Datagrid control. Please checkout the file WebForm1.aspx in my previous
email.

With the configuration as shown in WebForm1.aspx, the user control is
embedded in a datagrid control. When this file is executed and text is
entered into the user control textbox, LoadPostData() of the user
control is invoked. But even though LoadPostData() returns 'true', the
corresponding RaisePostDataChangedEvent() is not called. This is the
problem I am trying to find a solution to.

By the way, I am using Visual Studio.NET 2003 with .NET framework 1.1.
I think you are using Visual Studio.NET 2005 with .NET framework 2.0.
Nevertheless, I do not know if this would affect the result. I would
be curious though.

Thanks



Gaurav Vaish (www.EduJini.IN) wrote:
Quote:
Problem solved.
btw, the hidden field would be required because of the following reason:

For each ClientID that appears in the form and the control corresponding to
the same, the IPostBackDataHandler methods would be called.
And for no else.

Here's a trick:

Add a hidden field during 'Render' to the output.

You may download the code (that I wrote) from the following URL:
http://www.edujini.in/samples/ASP.Net/2.0/DataHandlerControl.zip


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


"Gaurav Vaish (www.EduJini.IN)" <gaurav.vaish.nospam (AT) nospam (DOT) gmail.com> wrote
in message news:OOulE4BwGHA.1288 (AT) TK2MSFTNGP02 (DOT) phx.gbl...
Let me give it a shot by creating a dummy 'UserControl' on my own.

--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


buzlite (AT) sympatico (DOT) ca> wrote in message
news:1155591996.737095.53890 (AT) b28g2000cwb (DOT) googlegroups.com...
Hello Gaurav,

I do not know the reasoning for adding a hidden field and what purpose
that would accomplish.

From the sample code attachments, when WebForm1.aspx is run and the
Datagrid generates MyUserControl user control, any text that is entered
in this user control TextBox would be properly posted back to the
server. This is true in that when MyUserControl.ascx.cs,
LoadPostData() is called, the data can be retrieved from the input
parameter of this method. So...this is working OK.

The problem is, when MyUserControl.ascx.cs, LoadPostData() returns a
value of 'true', RaisePostDataChangedEvent() is never invoked. In the
MyUserControl.ascx.cs code snippet, I hardcoded a return of 'true'.
Even then, RaisePostDataChangedEvent() is never invoked. This is the
main problem that I am experiencing.

Any insights ?

Thanks



Gaurav Vaish (www.EduJini.IN) wrote:
Hi,

The only missing thing that will need to fill, as I think, is a simple
hidden field... so that it can be captured in LoadPostData.

btw, what happens if you blindly return 'true' in LoadPostData?


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


buzlite (AT) sympatico (DOT) ca> wrote in message
news:1155567351.199524.188830 (AT) m79g2000cwm (DOT) googlegroups.com...
Hello All,
Any help would be appreciated.
Thanks



buzlite (AT) sympatico (DOT) ca wrote:
Hello All,


I've posted this in
microsoft.public.dotnet.framework.aspnet.datagridc ontrol but got not
reply so I'll try my luck here.

Any help would be greatly appreciated.
Thanks



I am having some difficulties with a user control implementing
IPostBackDataHandler when it is placed inside a datagrid.

I have created a user control (MyUserControl.ascx) containing 1
TextBox
that implements the IPostBackDataHandler.
I have also created a form (WebForm1.aspx) that contains 1 datagrid
of
which the datagrid contains the above user control as specified in
its
template.

The purpose is to dynamically create one MyUserControl for each item
in
the datasource for display and editing.

When the program is run and text is entered into MyUserControl's
textbox, the LoadPostData() of MyUserControl.ascx is called as
expected. But even though LoadPostData() returns true the
corresponding RaisePostDataChangedEvent() is not called.


Note: if I were to simply include the MyUserControl.ascx in
WebForm1.aspx, then both LoadPostData() and
RaisePostDataChangedEvent()
of MyUserControl.ascx are called as expected.

Would someone give me some insight as to why this is not working ?
Am
I missing a step somewhere ?



Attached is the bare essential code snippets to reproduce the
problem.


MyUserControl.ascx
-----------------------------------------------------
%@ Control Language="c#" AutoEventWireup="false"
Codebehind="MyUserControl.ascx.cs" Inherits="test.MyUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%
asp:TextBox id="TextBox1" runat="server"></asp:TextBox


MyUserControl.ascx.cs
-----------------------------------------------------
public class MyUserControl : System.Web.UI.UserControl,
IPostBackDataHandler, INamingContainer
{
protected System.Web.UI.WebControls.TextBox TextBox1;


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);

if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
}

/// <summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


public virtual bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
return true;
}

public virtual void RaisePostDataChangedEvent()
{
}

private void Page_Load(object sender, System.EventArgs e)
{
}
}



WebForm1.aspx
------------------------------------------------------
%@ Register TagPrefix="f4c" TagName="MyUserControl"
Src="MyUserControl.ascx" %
%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="test.WebForm1" %
...
form id="Form1" method="post" runat="server"
asp:datagrid id="dgListing" runat="server"
AutoGenerateColumns="False"
Columns
asp:TemplateColumn
ItemTemplate
f4c:MyUserControl id="MyUserControl1"
runat="server"></f4c:MyUserControl
/ItemTemplate
/asp:TemplateColumn
/Columns
/asp:datagrid
asp:Button id="Button1" runat="server" Text="Button"></asp:Button
/form


WebForm1.aspx.cs
------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{

...
private void Page_Load(object sender, System.EventArgs e)
{
//setup handlers
this.Button1.Click += new System.EventHandler(this.Button1_Click);

//setup datagrid
dgListing.DataSource = this.CreateDataSource();
dgListing.DataBind();
}

private void Button1_Click(object sender, System.EventArgs e)
{
}

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("SomeColumn", typeof(Int32)));

for (int i = 0; i < 2; i++)
{
dr = dt.NewRow();
dr[0] = i;
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}
}






Reply With Quote
  #10  
Old   
Gaurav Vaish \(www.EduJini.IN\)
 
Posts: n/a

Default Re: IPostBackDataHandler not working properly with DataGrid - 08-15-2006 , 08:55 PM



No problem.
Embed the control in DataGrid.... should not be a problem.

Did you try using my control in DataGrid?

--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


<buzlite001 (AT) hotmail (DOT) com> wrote

Quote:
Hello Gaurav,

Thanks for you attempt but it was not answering the initial problem.

The initial problem was that the MyUserControl is embedded in a
Datagrid control. Please checkout the file WebForm1.aspx in my previous
email.

With the configuration as shown in WebForm1.aspx, the user control is
embedded in a datagrid control. When this file is executed and text is
entered into the user control textbox, LoadPostData() of the user
control is invoked. But even though LoadPostData() returns 'true', the
corresponding RaisePostDataChangedEvent() is not called. This is the
problem I am trying to find a solution to.

By the way, I am using Visual Studio.NET 2003 with .NET framework 1.1.
I think you are using Visual Studio.NET 2005 with .NET framework 2.0.
Nevertheless, I do not know if this would affect the result. I would
be curious though.

Thanks



Gaurav Vaish (www.EduJini.IN) wrote:
Problem solved.
btw, the hidden field would be required because of the following reason:

For each ClientID that appears in the form and the control corresponding
to
the same, the IPostBackDataHandler methods would be called.
And for no else.

Here's a trick:

Add a hidden field during 'Render' to the output.

You may download the code (that I wrote) from the following URL:
http://www.edujini.in/samples/ASP.Net/2.0/DataHandlerControl.zip


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


"Gaurav Vaish (www.EduJini.IN)" <gaurav.vaish.nospam (AT) nospam (DOT) gmail.com
wrote
in message news:OOulE4BwGHA.1288 (AT) TK2MSFTNGP02 (DOT) phx.gbl...
Let me give it a shot by creating a dummy 'UserControl' on my own.

--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


buzlite (AT) sympatico (DOT) ca> wrote in message
news:1155591996.737095.53890 (AT) b28g2000cwb (DOT) googlegroups.com...
Hello Gaurav,

I do not know the reasoning for adding a hidden field and what purpose
that would accomplish.

From the sample code attachments, when WebForm1.aspx is run and the
Datagrid generates MyUserControl user control, any text that is
entered
in this user control TextBox would be properly posted back to the
server. This is true in that when MyUserControl.ascx.cs,
LoadPostData() is called, the data can be retrieved from the input
parameter of this method. So...this is working OK.

The problem is, when MyUserControl.ascx.cs, LoadPostData() returns a
value of 'true', RaisePostDataChangedEvent() is never invoked. In the
MyUserControl.ascx.cs code snippet, I hardcoded a return of 'true'.
Even then, RaisePostDataChangedEvent() is never invoked. This is the
main problem that I am experiencing.

Any insights ?

Thanks



Gaurav Vaish (www.EduJini.IN) wrote:
Hi,

The only missing thing that will need to fill, as I think, is a
simple
hidden field... so that it can be captured in LoadPostData.

btw, what happens if you blindly return 'true' in LoadPostData?


--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.org
http://www.edujini.in | http://webservices.edujini.in
-------------------


buzlite (AT) sympatico (DOT) ca> wrote in message
news:1155567351.199524.188830 (AT) m79g2000cwm (DOT) googlegroups.com...
Hello All,
Any help would be appreciated.
Thanks



buzlite (AT) sympatico (DOT) ca wrote:
Hello All,


I've posted this in
microsoft.public.dotnet.framework.aspnet.datagridc ontrol but got
not
reply so I'll try my luck here.

Any help would be greatly appreciated.
Thanks



I am having some difficulties with a user control implementing
IPostBackDataHandler when it is placed inside a datagrid.

I have created a user control (MyUserControl.ascx) containing 1
TextBox
that implements the IPostBackDataHandler.
I have also created a form (WebForm1.aspx) that contains 1
datagrid
of
which the datagrid contains the above user control as specified in
its
template.

The purpose is to dynamically create one MyUserControl for each
item
in
the datasource for display and editing.

When the program is run and text is entered into MyUserControl's
textbox, the LoadPostData() of MyUserControl.ascx is called as
expected. But even though LoadPostData() returns true the
corresponding RaisePostDataChangedEvent() is not called.


Note: if I were to simply include the MyUserControl.ascx in
WebForm1.aspx, then both LoadPostData() and
RaisePostDataChangedEvent()
of MyUserControl.ascx are called as expected.

Would someone give me some insight as to why this is not working ?
Am
I missing a step somewhere ?



Attached is the bare essential code snippets to reproduce the
problem.


MyUserControl.ascx
-----------------------------------------------------
%@ Control Language="c#" AutoEventWireup="false"
Codebehind="MyUserControl.ascx.cs" Inherits="test.MyUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%
asp:TextBox id="TextBox1" runat="server"></asp:TextBox


MyUserControl.ascx.cs
-----------------------------------------------------
public class MyUserControl : System.Web.UI.UserControl,
IPostBackDataHandler, INamingContainer
{
protected System.Web.UI.WebControls.TextBox TextBox1;


#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
base.OnInit(e);

if (Page != null)
{
Page.RegisterRequiresPostBack(this);
}
}

/// <summary
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


public virtual bool LoadPostData(string postDataKey,
System.Collections.Specialized.NameValueCollection postCollection)
{
return true;
}

public virtual void RaisePostDataChangedEvent()
{
}

private void Page_Load(object sender, System.EventArgs e)
{
}
}



WebForm1.aspx
------------------------------------------------------
%@ Register TagPrefix="f4c" TagName="MyUserControl"
Src="MyUserControl.ascx" %
%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="test.WebForm1" %
...
form id="Form1" method="post" runat="server"
asp:datagrid id="dgListing" runat="server"
AutoGenerateColumns="False"
Columns
asp:TemplateColumn
ItemTemplate
f4c:MyUserControl id="MyUserControl1"
runat="server"></f4c:MyUserControl
/ItemTemplate
/asp:TemplateColumn
/Columns
/asp:datagrid
asp:Button id="Button1" runat="server"
Text="Button"></asp:Button
/form


WebForm1.aspx.cs
------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{

...
private void Page_Load(object sender, System.EventArgs e)
{
//setup handlers
this.Button1.Click += new System.EventHandler(this.Button1_Click);

//setup datagrid
dgListing.DataSource = this.CreateDataSource();
dgListing.DataBind();
}

private void Button1_Click(object sender, System.EventArgs e)
{
}

ICollection CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("SomeColumn", typeof(Int32)));

for (int i = 0; i < 2; i++)
{
dr = dt.NewRow();
dr[0] = i;
dt.Rows.Add(dr);
}

DataView dv = new DataView(dt);
return dv;
}
}








Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.