J
Jeronimo Bertran
I have created some procedures to export the content of a gridView to a text
file. I am now trying to encapsulate all of this into a self contained
WebControl that basically behaves like an image button that when it is
clicked the export is performed.
I am not completely sure if the best approach is to define the control as a
PostBackEventHandler, but I created a WebControl defined as follows:
[ToolboxData("<{0}:GridViewExportButton runat=server></
{0}:GridViewExportButton>")]
public class GridViewExportButton : WebControl, IPostBackEventHandler
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Input;
}
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, "image");
writer.AddAttribute(HtmlTextWriterAttribute.Name, base.UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Src, this.ImageURL);
base.AddAttributesToRender(writer);
}
My first problem has to do with being able to link the correct gridView to
the control from the properties. I tried the following:
[Bindable(true)]
public GridView Grid
{
get
{
return (GridView)ViewState["Grid"];
}
set
{
ViewState["Grid"] = value;
}
}
This works very well in the designer since it shows a dropdownbox that allows
me to assign one of the existing gridviews on the page to the control.
However, I get the following error when it is interpreted:
Cannot create an object of type GridView from it string representation.
<cc1:GridViewExportButton ID="GridViewExportButton1" runat="server"
Grid="GridView1" OnClick="GridViewExportButton1_Click" />
My second problem has to do with the postback handler, when the user clicks
the control I need to execute server code that use the gridView object.
Thanks,
Jeronimo Bertran
file. I am now trying to encapsulate all of this into a self contained
WebControl that basically behaves like an image button that when it is
clicked the export is performed.
I am not completely sure if the best approach is to define the control as a
PostBackEventHandler, but I created a WebControl defined as follows:
[ToolboxData("<{0}:GridViewExportButton runat=server></
{0}:GridViewExportButton>")]
public class GridViewExportButton : WebControl, IPostBackEventHandler
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Input;
}
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, "image");
writer.AddAttribute(HtmlTextWriterAttribute.Name, base.UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Src, this.ImageURL);
base.AddAttributesToRender(writer);
}
My first problem has to do with being able to link the correct gridView to
the control from the properties. I tried the following:
[Bindable(true)]
public GridView Grid
{
get
{
return (GridView)ViewState["Grid"];
}
set
{
ViewState["Grid"] = value;
}
}
This works very well in the designer since it shows a dropdownbox that allows
me to assign one of the existing gridviews on the page to the control.
However, I get the following error when it is interpreted:
Cannot create an object of type GridView from it string representation.
<cc1:GridViewExportButton ID="GridViewExportButton1" runat="server"
Grid="GridView1" OnClick="GridViewExportButton1_Click" />
My second problem has to do with the postback handler, when the user clicks
the control I need to execute server code that use the gridView object.
Thanks,
Jeronimo Bertran