How do I add a required field validator in this scenario?
Simply putting a a validator in the edit item template does not work
<EditItemTemplate> |
<table cellpadding="0" cellspacing="0" border="0"> |
<tr valign="top"> |
<td> |
<asp:Label ID="lblValidFileTypesMessage" runat="server" Font-Size="X-Small" /> |
</td> |
</tr> |
<tr valign="baseline"> |
<td> |
<telerik:RadUpload ID="RadUpload1" runat="server" MaxFileInputsCount="1" InitialFileInputsCount="1" |
ControlObjectsVisibility="None" /> |
<br /> |
</td> |
</tr> |
</table> |
</EditItemTemplate> |
5 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 09 Mar 2010, 12:23 PM
Hello Jim,
I achieved same functionality by using CustomValidator control and checking whether any file is uploaded in RadUpload from client side validation method.
aspx:
javascript:
Thanks,
Princy.
I achieved same functionality by using CustomValidator control and checking whether any file is uploaded in RadUpload from client side validation method.
aspx:
<telerik:RadUpload ID="RadUpload1" runat="server"> |
</telerik:RadUpload> |
<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="ClientValidationFunction1" |
ErrorMessage="CustomValidator"> |
</asp:CustomValidator> |
javascript:
function ClientValidationFunction1(source, args) { |
args.IsValid = false; |
var ul = $find("<%= RadUpload1.ClientID %>"); |
var inputs = ul.getFileInputs(); |
for (i = inputs.length - 1; i >= 0; i--) { |
if (ul.getFileInputs()[i].value != "") { |
args.IsValid = true; |
return; |
} |
} |
} |
Thanks,
Princy.
0

Jim
Top achievements
Rank 1
answered on 09 Mar 2010, 10:42 PM
I am referring to an upload control in a grid. If you look at the example I provided, this upload control is inside an EditItemTemplate. You can't hardcode the RadUpload1.ClientId because the grid may have multiple rows, and the client ID would be different for each row. If you try to build it with your javascript, you get a build error.
I saw another example where somebody created the custom validator on the fly when the grid went into edit mode, but I was unable to get the validation event to fire.
Forum Example
I saw another example where somebody created the custom validator on the fly when the grid went into edit mode, but I was unable to get the validation event to fire.
Forum Example
0
Hi Jim,
I have attached sample project that demonstrates the approach. Basically it is RadUpload/CustomValidator inside the EditTemplate of RadGrid.
Sincerely yours,
Genady Sergeev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I have attached sample project that demonstrates the approach. Basically it is RadUpload/CustomValidator inside the EditTemplate of RadGrid.
Sincerely yours,
Genady Sergeev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0

Jim
Top achievements
Rank 1
answered on 16 Mar 2010, 07:31 PM
Hi Genady,
thanks for your reply. I have one additional issue that is preventing this from working for me. The grid I am using is in a user control, and I have not been able to get ClientScript.RegisterClientScriptBlock to work. It doesn't throw an error, it just doesn't fire. I modified it slightly:
I think that the script is not making it to the page that contains the control. The control is on a tabbed page that is being loaded like so:
Any ideas would be greatly appreciated.
thanks for your reply. I have one additional issue that is preventing this from working for me. The grid I am using is in a user control, and I have not been able to get ClientScript.RegisterClientScriptBlock to work. It doesn't throw an error, it just doesn't fire. I modified it slightly:
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "Upload", string.Format("window['UploadId'] = '{0}';", RadUpload1.ClientID), true); |
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!Page.IsPostBack) |
{ |
AddTab("Vendor Dashboard"); |
AddTab("Purchase Orders"); |
AddTab("Assets"); |
AddPageView(RadTabStrip1.FindTabByText("Vendor Dashboard")); |
} |
} |
private void AddTab(string tabName) |
{ |
RadTab tab = new RadTab(); |
tab.Text = tabName; |
RadTabStrip1.Tabs.Add(tab); |
} |
protected void RadMultiPage1_PageViewCreated(object sender, RadMultiPageEventArgs e) |
{ |
//The file name is the tab name with any spaces removed. |
string userControlName = e.PageView.ID.Replace(" ", "") + ".ascx"; |
Control userControl = Page.LoadControl(userControlName); |
userControl.ID = e.PageView.ID + "_userControl"; |
e.PageView.Controls.Add(userControl); |
} |
private void AddPageView(RadTab tab) |
{ |
RadPageView pageView = new RadPageView(); |
pageView.ID = tab.Text.Replace(" ", ""); |
RadMultiPage1.PageViews.Add(pageView); |
pageView.CssClass = "pageView"; |
tab.PageViewID = pageView.ID; |
tab.Selected = true; |
} |
0
Hello Jim,
You are completely right, the script is not making it to the page. I have prepared a workaround for this problem. You can find my modified project as an attachment. It should work in a LOD RadTabStrip scenario.
Regards,
Genady Sergeev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
You are completely right, the script is not making it to the page. I have prepared a workaround for this problem. You can find my modified project as an attachment. It should work in a LOD RadTabStrip scenario.
Regards,
Genady Sergeev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.