c# - Custom Validation if FileUpload is Empty my message is show -
this `.aspx` `fileuupload` .. <asp:fileupload id="fileupload1" runat="server" class="multi form-control" /> <asp:customvalidator id="validatorupload" runat="server" errormessage="file upload tidak boleh kosong" controltovalidate="fileupload1" display="dynamic" onservervalidate="validatorupload_servervalidate"></asp:customvalidator>
and .aspx.cs
(code behind).
protected void validatorupload_servervalidate(object source, servervalidateeventargs args) { fileupload upload = (fileupload)formview1.findcontrol("fileupload1"); httppostedfile hpf = upload.postedfile; if (((customcontrols_ddllocation)formview1.controls[0].findcontrol("ddl_location1")).selectedtext.tolower().trim() == "kelanis") { if (hpf.filename == null) { args.isvalid = false; } else { args.isvalid = true; } } }
i want show message if fileupload
empty
code isn't working. need solution this.
i have used one. works perfactly
<asp:fileupload id="fileupload1" runat="server" /> <br /> <asp:requiredfieldvalidator errormessage="required" controltovalidate="fileupload1" runat="server" display="dynamic" forecolor="red" /> <asp:regularexpressionvalidator id="regularexpressionvalidator1" validationexpression="([a-za-z0-9\s_\\.\-:])+(.doc|.docx|.pdf)$" controltovalidate="fileupload1" runat="server" forecolor="red" errormessage="please select valid word or pdf file file." display="dynamic" /> <br /> <asp:button text="submit" runat="server" />
for images can use following regular expression validator
([a-za-z0-9\s_\\.\-:])+(.png|.jpg|.gif)$
thanks
Comments
Post a Comment