I thought this would be straight forward, but doesnt look like and i have been trying for a while now.
I have a usercontrol on a web page. The web page also has a Telerik RadGrid. On the usercontrol, i am submitting some information and on success, i need to access the RadGrid from the usercontrol and rebind the RadGrid.
I have been trying the following code in UserControl, but i get 'Nothing'
Parent.Page.FindControl("RadGrid_Numbers")
Can someone please help? I am not sure what i am missing here.
I have a usercontrol on a web page. The web page also has a Telerik RadGrid. On the usercontrol, i am submitting some information and on success, i need to access the RadGrid from the usercontrol and rebind the RadGrid.
I have been trying the following code in UserControl, but i get 'Nothing'
Parent.Page.FindControl("RadGrid_Numbers")
Can someone please help? I am not sure what i am missing here.
6 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 15 Feb 2014, 06:52 AM
Hi ,
I guess you want to access the Grid in its UserControl. Here is a sample i have tried. Please have a look, if this doesn't help, provide your full code snippet.
ASPX:
ASCX:
ASCX.CS:
Thanks,
Shinu
I guess you want to access the Grid in its UserControl. Here is a sample i have tried. Please have a look, if this doesn't help, provide your full code snippet.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"OrderID"
DataField
=
"OrderID"
HeaderText
=
"OrderID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ShipCity"
HeaderText
=
"ShipCity"
UniqueName
=
"ShipCity"
/>
</
Columns
>
<
EditFormSettings
UserControlName
=
"0UserControl.ascx"
EditFormType
=
"WebUserControl"
EditColumn-UniqueName
=
"EditCommandColumn1"
>
</
EditFormSettings
>
</
MasterTableView
>
</
telerik:RadGrid
>
ASCX:
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text
=
"Some Text"
></
asp:Label
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Submit"
OnClick
=
"Button1_Click"
/>
ASCX.CS:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
RadGrid rad = (RadGrid)Parent.Page.FindControl(
"RadGrid1"
);
rad.MasterTableView.GetColumn(
"ShipCity"
).Visible =
false
;
rad.Rebind();
}
Thanks,
Shinu
0

first
Top achievements
Rank 1
answered on 15 Feb 2014, 12:33 PM
The user control in or part of the grid. It is external to the grid but on the same aspx page. Below is the sample. Please suggest
ASPX Page:
UserControl - ASCX
ASCX.VB (code behind for usercontrol)
In the usercontrol, on submit button click, i am showing the RadWindow to show confirmation message that the data successfully got submitted. The RadWindow has an 'OK' button, which closes itself. Upon closing or before showing the RadWindow, i want to Rebind my RadGrid which is on the ASPX page to reflect the saved data.
Please suggest.
ASPX Page:
<!-- RadGrid -->
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
UniqueName
=
"Numbers"
DataField
=
"num"
HeaderText
=
"Numbers"
>
</
telerik:GridBoundColumn
>
...
...
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<!--UserControl -->
<
telerik:RadPanelBar
ID
=
"RadPanelBar1"
runat
=
"server"
Skin
=
"Default"
Width
=
"100%"
>
<
Items
>
<
telerik:RadPanelItem
runat
=
"server"
Text
=
""
Value
=
"TestHeader"
CssClass
=
"clsPanelItem"
>
<
HeaderTemplate
>
<!--the below span is required to display expand/collapse images-->
<
span
class
=
"rpExpandHandle"
></
span
>
<
telerik:RadListView
ID
=
"RadListView_TestHeader"
runat
=
"server"
>
<
EmptyDataTemplate
>
<
span
><
b
>Test Form</
b
> </
span
>
</
EmptyDataTemplate
>
<
ItemTemplate
>
</
ItemTemplate
>
<
ItemTemplate
>
<
span
><
b
>Test Form</
b
> </
span
>
</
ItemTemplate
>
</
telerik:RadListView
>
</
HeaderTemplate
>
<
Items
>
<
telerik:RadPanelItem
runat
=
"server"
Text
=
""
Value
=
"TestDetail"
CssClass
=
"clsPanelItem"
>
<
ItemTemplate
>
<
uc:TestForm
ID
=
"UserControl_TestForm"
runat
=
"server"
/>
</
ItemTemplate
>
</
telerik:RadPanelItem
>
</
Items
>
</
telerik:RadPanelItem
>
</
Items
>
</
telerik:RadPanelBar
>
UserControl - ASCX
<
asp:TextBox
ID
=
"TextBox_Test"
runat
=
"server"
/>
<
div
class
=
"Submit"
>
<
asp:Button
ID
=
"Button_Submit"
runat
=
"server"
Text
=
"Submit"
onclick
=
"Button_Submit_Click"
></
asp:Button
>
</
div
>
<
telerik:RadWindowManager
ID
=
"RadWindowManager_TestForm"
runat
=
"server"
EnableShadow
=
"true"
VisibleStatusbar
=
"false"
>
<
Windows
>
<
telerik:RadWindow
AutoSize
=
"true"
Behaviors
=
"Close"
Modal
=
"true"
runat
=
"server"
ID
=
"RadWindow_ShowDialog"
OpenerElementID
=
"Button_Save"
Title
=
"Test Form"
>
<
ContentTemplate
>
<
div
style
=
"width:410px;margin:5px;height:40px"
>
<
asp:Label
runat
=
"server"
ID
=
"Label_Dialog"
class
=
"contentPink"
Text
=
""
/>
</
div
>
<
div
class
=
"PopupButtons"
>
<
br
/>
<
asp:Button
ID
=
"Button_Close"
runat
=
"server"
Text
=
"Ok"
Width
=
"50px"
OnClientClick
=
"CloseDialog();return false;"
/>
</
div
>
</
ContentTemplate
>
</
telerik:RadWindow
>
</
Windows
>
</
telerik:RadWindowManager
>
<
script
type
=
"text/javascript"
language
=
"javascript"
>
function CloseDialog() {
$find("<%= RadWindow_ShowDialog.ClientID %>").close();
}
</
script
>
ASCX.VB (code behind for usercontrol)
Protected
Sub
Button_Submit_Click(sender
As
Object
, e
As
EventArgs)
Handles
Button_Submit.Click
SaveTestForm()
'Saves the form in database
Dim
script
As
String
=
"function f(){$find("
""
+ RadWindow_ShowDialog.ClientID &
""
").show();}Sys.Application.add_load(f); "
ScriptManager.RegisterStartupScript(Page, Page.[
GetType
](),
"key"
, script,
True
)
End
Sub
In the usercontrol, on submit button click, i am showing the RadWindow to show confirmation message that the data successfully got submitted. The RadWindow has an 'OK' button, which closes itself. Upon closing or before showing the RadWindow, i want to Rebind my RadGrid which is on the ASPX page to reflect the saved data.
Please suggest.
0

first
Top achievements
Rank 1
answered on 16 Feb 2014, 02:19 PM
I found the solution; referred to this link - AjaxRequest. If you have any other alternate approach, let me know.
0

first
Top achievements
Rank 1
answered on 17 Feb 2014, 07:25 PM
However i have one problem here, along with RadGrid (no issues with Radgrid, it rebinds nicely), i also have to repopulate a ASP.NET textbox control. I have registered the asp.net textbox in the ajaxmanager, also the code is in place (i can see the correct values getting assigned to the textbox, but it doesnt reflect the new values (still shows the old value)).
Please suggest.
Please suggest.
0

first
Top achievements
Rank 1
answered on 17 Feb 2014, 09:04 PM
Forgot to mention, i am reading the value from database (using datatable), and appending it to this TextBox.
Anyone from telerik team?
Anyone from telerik team?
0

first
Top achievements
Rank 1
answered on 18 Feb 2014, 12:32 AM
Never mind, i solved the issue. It was something in my code that was creating conflicts.