Referencing User Control In Some Other User Control

hi,

I have two user controls namely CanvasGrid.ascx and GridUtility.ascx. CanvasGrid.ascx is just a container for displaying GridView control in a placedholder GridPH. I want to get the checked rows from GridView control of CanvasGrid.ascx and do tagging against specific name selected from the TagDropDownList of GridUtility.ascx. But the problem is that I am not geting the reference of GridView as it is coming null everytime even when I am using FindControl() to find the GridView control on the page. GridUtility.ascx is a part of CanvasGrid.ascx and it is placed in a placeholder GridUtilityPH using LoadControl() at pageLoad of CanvasGrid.ascx

 Awaiting for reply

Thanks

Abhijit


Abhijit C Bakshi
0
abhijitcb 11/2/2007 8:01:00 AM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 30 followers.

💬 7 Replies
👁️‍🗨️ 84 Views

do you have explicit reference of the usercontrol you are dynamically trying to load?

0
mahesh_p_k 11/2/2007 5:17:39 PM

CanvasGrid.ascx has a explicit reference of GridUtility UserControl but other way round is not true

CanvasGrid.ascx Code snippet

<%
@ Control Language="C#" AutoEventWireup="true" CodeFile="CanvasGrid.ascx.cs" Inherits="Panels_CanvasGrid" %>

<%@ Register Src="GridUtility.ascx" TagName="GridUtility" TagPrefix="uc1" %>

 

GridUtlity.ascx code snippet

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="GridUtility.ascx.cs" Inherits="Panels_GridUtility" %>


Abhijit C Bakshi
0
abhijitcb 11/3/2007 6:45:01 AM

abhijitcb:

I have two user controls namely CanvasGrid.ascx and GridUtility.ascx. CanvasGrid.ascx is just a container for displaying GridView control in a placedholder GridPH. I want to get the checked rows from GridView control of CanvasGrid.ascx and do tagging against specific name selected from the TagDropDownList of GridUtility.ascx. But the problem is that I am not geting the reference of GridView as it is coming null everytime even when I am using FindControl() to find the GridView control on the page. GridUtility.ascx is a part of CanvasGrid.ascx and it is placed in a placeholder GridUtilityPH using LoadControl() at pageLoad of CanvasGrid.ascx

Hi Abhijit,
Have you try the following code with loadcontrol method in your web form page.
protected void Page_Load(object sender, EventArgs e)
    {
        Control ctl = Page.LoadControl("~/CanvasGrid.ascx ");
        Control gridview_control = ctl.FindControl("Gridview_id");
        Session["GridView"] = gridview_control;
}
The code snippet above put the gridview_control into a session object; therefore, you can access
the gridview control by the session object in another user control.

Hope this Information is helpful!
Xun

 


Regards,
Xun Ye.
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that
helps you, and to click “Unmark as Answer” if a marked post
does not actually answer your question. This can be beneficial
to other community members reading the thread.
0
Xun 11/6/2007 8:09:22 AM

Yeah this looks quite helpful.

thanks alot. giving a try on it.


Abhijit C Bakshi
0
abhijitcb 11/6/2007 1:02:26 PM

I devised a solution to make two usercontrol interact with each other.

http://abhijitcb.blogspot.com/2007/11/interacting-between-user-controls.html

 

 


Abhijit C Bakshi
0
abhijitcb 11/7/2007 6:02:43 AM

Hi Abhijit,

Your solution is great!

Xun


Regards,
Xun Ye.
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that
helps you, and to click “Unmark as Answer” if a marked post
does not actually answer your question. This can be beneficial
to other community members reading the thread.
0
Xun 11/7/2007 6:09:24 AM

Smile thanks... if you have any other ideas to flow then please let me know.


Abhijit C Bakshi
0
abhijitcb 11/7/2007 6:20:54 AM
Reply: