views:

482

answers:

3

I'm using a telerik RadGrid, with a UserControl edit form. When the InsertCommand event fires, I get the user control, and find edit controls on it, but there Text properties are all string.Empty. I suspect this has something to do with ViewState, but I don't know where to begin looking.

protected void jobGrid_InsertCommand(object source, GridCommandEventArgs e)
{
    var editControl = e.Item.FindControl(GridEditFormItem.EditFormUserControlID) as JobEditControl;
    SqlJobProvider.InsertJob(GetFieldValues(editControl));
}

private Dictionary<string, object> GetFieldValues(UserControl editControl)
{
    string tb = (editControl.FindControl("aspText") as TextBox).Text;
+1  A: 

Check your Page_Load first and make sure you are not resetting everything there with each hit to the page. If you do not have a !IsPostBack, you probably are. That is the most common reason for not getting values when you post.

Gregory A Beamer
I have populate the grid on each postback, otherwise actions like sorting or filtering result in an empty grid.
ProfK
+2  A: 

I believe your controls are empty because you are rebinding the grid before the inserted event. To avoid such behavior I suggest you populate RadGrid using the NeedDataSource event. It is fired whenever the grid needs rebinding.

korchev
A: 

Use: Private Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand Dim insertedItem As GridEditableItem = e.Item.OwnerTableView.GetInsertItem()

    Dim _userControl As UserControl = CType(insertedItem.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)

... http://www.telerik.com/help/aspnet/grid/grdinsertingvaluesusercontrolformtemplate.html

Mario