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

[Solved] Getting values back from WebUserControl

4 Answers 138 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Deon van Staden
Top achievements
Rank 1
Deon van Staden asked on 11 Feb 2009, 10:20 PM
I have a custom UserControl set for the editing on the GridControl.
I need to get the Text value from a TextBox on this UserControl back to the Server.

Sofar, I tried to access this using the following:

UserControl userControl = (UserControl)e.Item.FindControl GridEditFormItem.EditFormUserControlID);  
string result = (userControl.FindControl("txtNote") as TextBox).Text; 




This is returning "" on the server side. 

How can I perform a postback on this textbox in order for the Server to get the values from the client?

Any help please?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Feb 2009, 05:02 AM
Hi,

You can try the following code snippet in the ItemDataBound event to access the TextBox value from the UserControl when the Grid is in edit mode.

CS:
  protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode)) 
        { 
            GridEditFormItem editform = (GridEditFormItem)e.Item; 
            UserControl userControl = (UserControl)editform.FindControl(GridEditFormItem.EditFormUserControlID); 
            string result = (userControl.FindControl("txtNote"as TextBox).Text;  
        } 
   } 


Try the below given code to access the Updated text from the TextBox when the Update button is clicked.

CS:
 protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
        GridEditFormItem editform = (GridEditFormItem)e.Item; 
        UserControl userControl = (UserControl)editform.FindControl(GridEditFormItem.EditFormUserControlID);   
        string result = (userControl.FindControl("txtNote"as TextBox).Text;  
 
    } 

Thanks
Shinu
0
Sean
Top achievements
Rank 1
answered on 14 Apr 2009, 04:58 PM
Do you have this in a VB.net Sample?
0
Sean
Top achievements
Rank 1
answered on 14 Apr 2009, 08:50 PM
I changed the code to this

 
Dim editform As GridEditFormItem = e.Item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim userControl As UserControl = editform.FindControl(GridEditFormItem.EditFormUserControlID)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim result As String = CType(userControl.FindControl("textbox11"), TextBox).Text<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(result) 


and got  "Object reference not set to an instance of an object."



0
Yavor
Telerik team
answered on 15 Apr 2009, 06:18 AM
Hello Sean,

The following example demonstrates in practice how to reference the user control elements, and handle the update.
I hope it helps.

Best wishes,
Yavor
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.
Tags
Grid
Asked by
Deon van Staden
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Sean
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or