I have a custom server control that inherits from the GridView Class. This all works but I wanted to add a Hidden Field to the control so that I could pass some data back to the server from some client javascript code.
1) What is the best way to add a Hidden Field to the control without implementing the Composite Server Control? It looks like the Composite Server control would do the job, except that I assume that I would then have to add all the GridView
pub variables as public properties and link everything up. This looks like a lot of work... I would like to be able to stick to inheriting from GridView since all this is done for me.
I did try to add code to the render method (and the hidden field is rendered on the page) but it seems like the ValueChanged event is never called. (See code below)
2) Is there a better way for client javascript to pass data back to the server without using a hidden field. Maybe I am missing a more obvious way of doing this.
I know this is a really old question but I came up on a google search and it took me some time to find out.
The easiest way to add a HiddenField in an inheriteted GridView is to override the CreateChildControls method, the one with parameters that returns an int.
protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding)
{
var rowCount = base.CreateChildControls(dataSource, dataBinding);
_hiddenField = new HiddenField();
_hiddenField.ID = ID + "HiddenField";
_hiddenField.Value = "";
Controls.Add(_hiddenField);
return rowCount;
}
wadec
Member
45 Points
9 Posts
Custom Server Control that inherits from GridView + Hiddenfield...
Jul 25, 2006 09:16 PM|LINK
I have a custom server control that inherits from the GridView Class. This all works but I wanted to add a Hidden Field to the control so that I could pass some data back to the server from some client javascript code.
1) What is the best way to add a Hidden Field to the control without implementing the Composite Server Control? It looks like the Composite Server control would do the job, except that I assume that I would then have to add all the GridView pub variables as public properties and link everything up. This looks like a lot of work... I would like to be able to stick to inheriting from GridView since all this is done for me.
I did try to add code to the render method (and the hidden field is rendered on the page) but it seems like the ValueChanged event is never called. (See code below)
2) Is there a better way for client javascript to pass data back to the server without using a hidden field. Maybe I am missing a more obvious way of doing this.
Thanks for your help.
WadeCprotected override void Render(HtmlTextWriter writer)
{
HiddenField LastCell.ID = "lastcell";
LastCell.EnableViewState = true;
LastCell.ValueChanged += new EventHandler(LastCellChanged);
LastCell.RenderControl(writer);
base.Render(writer);
}
void LastCellChanged(object sender, EventArgs args)
{
Save();
}
gissolved
Member
2 Points
1 Post
Re: Custom Server Control that inherits from GridView + Hiddenfield...
Dec 19, 2011 02:00 PM|LINK
I know this is a really old question but I came up on a google search and it took me some time to find out.
The easiest way to add a HiddenField in an inheriteted GridView is to override the CreateChildControls method, the one with parameters that returns an int.
protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding) { var rowCount = base.CreateChildControls(dataSource, dataBinding); _hiddenField = new HiddenField(); _hiddenField.ID = ID + "HiddenField"; _hiddenField.Value = ""; Controls.Add(_hiddenField); return rowCount; }Succes,
Samuel
http://gissolved.blogspot.com