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

[Solved] How to access RadUpload control in a grid for server side validation

5 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
FreshOne
Top achievements
Rank 1
FreshOne asked on 09 Feb 2010, 09:30 AM
hi all,
i have a RadUpload control in a RadGrid. i added a CustomValidator, i'm validating file extensions in a javascript function, and i need to validate the file size in a server side function bcoz this can't be validated on client side except if i had a RadProgressArea, which i don't (like this example http://www.telerik.com/help/aspnet-ajax/upload_howtoclientfilesize.html).

so i need to add "OnServerValidate" function to the CustomValidator, the problem is how can i access the RadUpload control in this function??

am i in the correct way, or the whole approach is not applicable? how can i do it?

thnx in advance

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Feb 2010, 10:45 AM
Hi,

Try the code snippet below  to access a  RadUpload control  in the "OnServerValidate" function of the CustomValidator.You can use the GridEditableItem if you want to access it in the edit mode or the GridDataItem if in normal mode.

C#
 protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) 
    { 
        GridEditableItem editedItem = (GridEditableItem)(source as RadUpload).NamingContainer; 
        RadUpload rdUpload = (RadUpload)editedItem["ColumnUniqueName"].FindControl("RadUpload1"); 
 
    } 


Thanks,
Shinu
0
FreshOne
Top achievements
Rank 1
answered on 09 Feb 2010, 11:19 AM
hey Shinu, thnx for ur reply

i'm getting an exception on this line
Dim editedItem As GridEditableItem = DirectCast(TryCast(source, RadUpload).NamingContainer, GridEditableItem)  
 

System.NullReferenceException: Object reference not set to an instance of an object.
0
FreshOne
Top achievements
Rank 1
answered on 14 Feb 2010, 08:36 AM
i couldn't figure it out yet..any ideas would be really appreciated
0
Accepted
Princy
Top achievements
Rank 2
answered on 17 Feb 2010, 06:54 AM
Hi,

Please try the code snippet instead as  shown below to access the RadUpload control on edit and insert:

C#
   protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) 
        { 
 
            if (RadGrid1.MasterTableView.IsItemInserted != false
            { 
                GridEditFormInsertItem insertItem = (GridEditFormInsertItem)(source as CustomValidator).NamingContainer; 
                RadUpload rdUpload = (RadUpload)insertItem["ColumnUniqueName"].FindControl("RadUpload1");  
            } 
            else 
            { 
                GridEditableItem editedItem = (GridEditableItem)(source as CustomValidator).NamingContainer; 
                RadUpload rdUpload = (RadUpload)editedItem["ColumnUniqueName"].FindControl("RadUpload1"); 
            } 
            
  
   
        } 


Thanks,
Princy
0
FreshOne
Top achievements
Rank 1
answered on 18 Feb 2010, 06:45 AM
thnx a lot Princy it worked like a charm, really appreciated
Tags
Grid
Asked by
FreshOne
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
FreshOne
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or