This is a migrated thread and some comments may be shown as answers.

[Solved] Setting a public property of user control in grid insert/update mode

4 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Morten
Top achievements
Rank 2
Iron
Iron
Iron
Morten asked on 10 Jul 2009, 02:05 PM
in the article http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesusercontrolformtemplate.html it is well explained how to set properties of controls inside a user control, when a user control is being used as an insert/update form in a radgrid.

How do I set a public property of that same user control?


4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 13 Jul 2009, 03:07 PM
Hi Morten,

If you have defined public properties for your UserControl class, you can access them through the following way:

1. In your .ascx  control markup file, set the ClassName property in the <%@ Register %> directive. This name defines the class name of your custom user control. Suppose I have a control named GridControl that I want to reference. I use:

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


2. In your including .aspx page, use two types of directives to register and reference the control type:

<%@ Register Src="~/GridControl.ascx" TagPrefix="my" TagName="GridControl" %> 
<%@ Reference Control="~/GridControl.ascx" %> 

This is it. Now in the codebehind, my custom user control is referrable to its ID directly as specified on the page. In RadGrid's InsertCommand event, you can now use:

GridControl myEditorControl = e.Item.FindControl("GridControl1"as GridControl; 
//myEditorControl with all of its public properties and methods 

This is all. Your user control is now usable just like any other server control or custom object.

Best wishes,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Josh
Top achievements
Rank 1
answered on 31 Aug 2009, 02:49 PM
Please disregard, I found the answer I was looking for.
0
Josh
Top achievements
Rank 1
answered on 31 Aug 2009, 03:11 PM
Hi all,

Actually, I didn't find the solution I was looking for. 

I have the same need as the original poster, but the solution is not working for me. I have set up the code exactly as shown below but Visual Studio (2005) doesn't recognize the GridControl type.  It has underlined GridControl in both places.

GridControl myEditorControl = e.Item.FindControl(
"GridControl1"as GridControl

Also, I don't know what GridControl1 is supposed to refer to in the code above.

I don't know what to do.

Josh
0
Veli
Telerik team
answered on 03 Sep 2009, 10:31 AM
Hi Josh,

GridControl is the type of your custom control, while GridControl1 is the ID of the user control instance you have placed in your page. Did you follow my suggestion? Sometimes VS has problems properly referencing user controls, so you may want to rebuild your project.

Best wishes,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Morten
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Veli
Telerik team
Josh
Top achievements
Rank 1
Share this question
or