Hi ,
I am creating a column Image Button dynamical but when i click on image entire page is post back and my dynamically created column are disappeared (not persist).
Below are the code
void GridUserControl_OnInitializeRow(RowEventArgs e){ var objCustomItemTemplateEdit = new EditCustomItemTemplate(); objCustomItemTemplateEdit.ID = "Edit_" + selectedSpecialty; e.Row.Items[3].Template = objCustomItemTemplateEdit;
var objCustomItemTemplateDelete = new DeleteCustomItemTemplate(); objCustomItemTemplateDelete.ID = "Delete_" + selectedSpecialty; e.Row.Items[4].Template = objCustomItemTemplateDelete;}
public class EditCustomItemTemplate : ITemplate { public string ID { get; set; } public string CommandArg { get; set; }
public void InstantiateIn(Control container) { ImageButton p = new ImageButton(); p.ID = ID; p.EnableViewState = true; p.CommandArgument = CommandArg; p.CommandName = "Edit"; p.ViewStateMode = ViewStateMode.Enabled; p.ImageUrl = "Edit.png"; container.Controls.Add(p); }
}
public class DeleteCustomItemTemplate : ITemplate { public string ID { get; set; } public string CommandArg { get; set; }
public void InstantiateIn(Control container) { ImageButton p = new ImageButton(); p.ID = ID; p.EnableViewState = true; p.CommandArgument = CommandArg; p.CommandName = "Delete"; p.ViewStateMode = ViewStateMode.Enabled; p.ImageUrl = "dele.png" p.OnClientClick = "return confirm('Are you sure you want to delete this record?');"; container.Controls.Add(p); } }
Hello Santosh,
Thank you for the code provided. It is working as expected - I have tried it in a sample of mine. Clicking on the templates does not cause any issues in the app. Please provide more context on how you create the dynamical columns, so that I can try to replicate this in my sample and investigate.
We have one User Control and it that User control we have WebDataGrid. Same User Control are used in every Client view page.
We are defining column in xml file from that it picking up column name which has to be shown in the screen. Same xml file is read at every time when data (DataTable or List) is assigned to a grid data source.
I had on method BindDataToGrid() , If i called mention method at every post back then after clicking on image button not disappear but unnecessary database is hit.
With this on my dynamically generated column when i clicked "ItemCommand" event is not get fired.
Can you please share your sample code ...
If you are experiencing the same this is expected. The resolution is to bind the grid on isPostBack, rather than on !isPostBack. As discussed there is another thread open for discussing the ItemCommand not firing issue.
Hi Hristo,
Yes i am experiencing same only after image click page is post back and image buttons in the grid are disappeared plus item command event is also not fire .... :(
Thanks,
Santosh.
Hi Santosh,
Thank you for your response.
When binding the grid on !isPostBack, then when clicking the image button the page will reload, but the grid will be empty. This is expected, because it cannot find its datasource in order to bind. This will happen on each postback regardless if it is the image button that caused it.
Is this the behavior you are experiencing too, or you see the grid is populated after postback and only the image buttons are gone ? Please let me know.
To provide more insight let me note that the WebDataGrid is a server control and is designed in such a way that it is expected to be bound on each postback. This is also a requirement for the Sorting, Paging and Filtering behaviors to work.
I am looking forward to hearing from you.
HI ,
Thanks for immediate reply ...
2) then edit and delete image which are dynamically bind are disappear
I was not able to experience this behavior
For above scenario please do the below thing
1. If Not PostBack code bind the data from the DB
2. Dynamically Edit and Delete Image button will be visible
3. Click on Edit button
4. Page postback will be called and Image button will be not be visible. i also try using "EnsureTemplates" method of grid but bad luck.
Thank you for the code shared. I was able to run e sample ( it is the sample you had sent in another tickets, so pretty much it is the same). Please find my comments below:
1) Both As post back happens:
The Edit and Delete buttons are server side controls and are expected to cause post backs
3) plus ItemCommand event is also not fired
This issue is being investigated in thie support ticket as well: http://es.infragistics.com/community/forums/t/109378.aspx
Please do not open duplicate tickets from now on as this will interfere with Infragistics policy.