Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

I am using one user control in that i have added a grid view to display,edit,update and delete the records. I have call that user control dynamically in my code and passed req value to it. I have a tree view base on that it will show me the grid in that user control. But now the problem is when i am going to click on edit or delete link of grid view the user control disappear[which causes grid view to be disappear]. So what can i do to handle this issue. how i can get call to edit,delete,update methods of grid view.
Posted
Comments
syed shanu 1-Dec-14 1:21am    
where do you call your User Control Dynamically .example in button click,Page load etc and can you paste your code here.
Member 11151142 1-Dec-14 3:50am    
I have call user control on treeview link click,as follows

if (TreeView1.SelectedNode.ToolTip == "SiteName")
{
UserControls_Site_SiteUC usercntl = (UserControls_Site_SiteUC)Page.LoadControl("~/UserControls/Site/SiteUC.ascx");
usercntl.SiteID = int.Parse(PID.ToString());
}

it will show me the write grid view base on treeview node click but when i am going to click on edit or delete link of grid view the user control disappears.
It will not call the gridview delete or modechanging method
syed shanu 1-Dec-14 3:52am    
You can find the Solution below As Mr.Kornfeld Eliyahu Peter told.
Member 11151142 1-Dec-14 4:00am    
Thank you.
syed shanu 1-Dec-14 4:03am    
You can check here few links related to loading User control at runtime.

http://www.codeproject.com/Articles/59781/Dynamic-Loading-of-ASP-NET-User-Controls
http://www.codeproject.com/Articles/26589/Dynamically-add-and-remove-user-controls

http://forums.asp.net/t/1608954.aspx?Dynamic+Add+of+Web+User+Control

http://www.c-sharpcorner.com/UploadFile/d3e4b1/dynamically-loading-usercontrol-into-webpage-using-Asp-Net/

1 solution

A dynamic control must be re-created on each and every post to the page, not only on the first creation!
When you hit one of your buttons on the grid, the click initiates a post-back to the server, but in that flow you do not create your dynamic control so it disappears from the page...
You can save yourself a lot of work and network usage if you learn using AJAX...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900