CompreValidator for Textbox and FileUpload
-
I have to validate 1 textbox and 1 FileUpload control on my page. I have make the user to fill at least one of them, i.e. both of them can not be left blank. Do anybody have any idea about how can use the CompareValidator for this. Thank you.
anada8886 wrote:
I have to validate 1 textbox and 1 FileUpload control on my page
Use customvalidator and javascript function..! or use server side validation..!
anada8886 wrote:
can use the CompareValidator for this.
why would you go for compare validator..! Is it manadatory..?:confused:
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
anada8886 wrote:
I have to validate 1 textbox and 1 FileUpload control on my page
Use customvalidator and javascript function..! or use server side validation..!
anada8886 wrote:
can use the CompareValidator for this.
why would you go for compare validator..! Is it manadatory..?:confused:
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
Thanks for the reply. I have already tried using Custom validator with Javascript but it is giving me some JS error. And it is giving that error only for Custom validator,that is why I thought if it can be done using CompareValidator. Secondly ,I want it in client side only,it should not go to server side.
-
Thanks for the reply. I have already tried using Custom validator with Javascript but it is giving me some JS error. And it is giving that error only for Custom validator,that is why I thought if it can be done using CompareValidator. Secondly ,I want it in client side only,it should not go to server side.
anada8886 wrote:
I thought if it can be done using CompareValidator.
the answer is no ..!You cant do it with comparevalidator..! the compare validator checks if both the values are identical or not ..! thts it..!
<script language ="javascript" type ="text/javascript" >
function CheckEmpty() {
var fromaddress = document.getElementById('<%= TextBox1.ClientID %>').value;
var fromaddress1 = document.getElementById('<%= FileUpload1.ClientID %>').value;
if (fromaddress=="" && fromaddress1=="") {alert("Should not be empty"); } } </script> <div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="should not be blank..!"
ClientValidationFunction="CheckEmpty"></asp:CustomValidator></div> <asp:Button ID="Button1" runat="server" Text="Button" /> </form>
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
anada8886 wrote:
I thought if it can be done using CompareValidator.
the answer is no ..!You cant do it with comparevalidator..! the compare validator checks if both the values are identical or not ..! thts it..!
<script language ="javascript" type ="text/javascript" >
function CheckEmpty() {
var fromaddress = document.getElementById('<%= TextBox1.ClientID %>').value;
var fromaddress1 = document.getElementById('<%= FileUpload1.ClientID %>').value;
if (fromaddress=="" && fromaddress1=="") {alert("Should not be empty"); } } </script> <div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="should not be blank..!"
ClientValidationFunction="CheckEmpty"></asp:CustomValidator></div> <asp:Button ID="Button1" runat="server" Text="Button" /> </form>
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
Thanks for your reply sir, but as I told you using CustomValidator is giving me error - 'Microsoft JScript runtime error: Object required',in the method WebForm_RemoveClassName(element, className) of WebResource.axd.
anada8886 wrote:
Thanks for your reply sir
You no need to call any one as sir in here. ..! then remove the custom validator..!and add the function for button click client validation..! as shown below..! Check
OnClientClick="CheckEmpty();"
<asp:Button ID="Button1" runat="server" OnClientClick="CheckEmpty();" Text="Button" />
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
anada8886 wrote:
Thanks for your reply sir
You no need to call any one as sir in here. ..! then remove the custom validator..!and add the function for button click client validation..! as shown below..! Check
OnClientClick="CheckEmpty();"
<asp:Button ID="Button1" runat="server" OnClientClick="CheckEmpty();" Text="Button" />
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.
-
anada8886 wrote:
Hey thanks, it worked !!!
Any Time..!:thumbsup: Here it is a tradition to mark it as answer if it helps..!
LatestArticle :Log4Net Why Do Some People Forget To Mark as Answer .If It Helps.