Click here to Skip to main content
15,921,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<form id="form1" runat="server">
<asp:Panel runat="server" ID="pnlHeader" Visible="true">
    Search:<br />
    <asp:TextBox runat="server" id="tbxSearch" />
    <asp:RequiredFieldValidator runat="server" id="reqSearch" controltovalidate="tbxSearch" errormessage="(Required)" />
    <asp:Button runat="server" id="btnSearch" text="Search" />
</asp:Panel>
<br />
<br />
<asp:Panel ID="pnlUpload" runat="server" Visible="false">
<asp:FileUpload ID="fileUpload" runat="server" />
       <asp:Button ID="btnUpload" Text="Upload" runat="server"OnClick="btnUpload_Click"/>
<asp:RequiredFieldValidator ID="reqFileUpload" runat="server" ControlToValidate="fileUpload" ErrorMessage="File Required!" />
</asp:Panel>
</form>

Condition:
1. Enter some data on search textbox – click on the search button. The pnlUpload would be displayed. And if you click on the search button with null value on the search textbox then it would be showing the requirement field validation.
2. Once the first step is valid then the pnlUpload would be visible to true. And if you click on the upload button then, it would be displayed the message of File Required! . and if we select a file and click upload things would go fine. But if I select the file on the fileupload control and remove the value from the tbxSearch and click on the upload button the process would be continued.
My issue is how can we stop the process until and unless the both validations take place in right way.

Thanks in advance.
Posted
v3

1 solution

You have to use onclientclick of button and style="visibility:hidden;" property of panel,make it visible from javascript.Try following code
XML
<asp:Panel runat="server" ID="pnlHeader" Visible="true">
    Search:<br />
    <asp:TextBox runat="server" id="tbxSearch" />
    <asp:RequiredFieldValidator runat="server" id="reqSearch" controltovalidate="tbxSearch" errormessage="(Required)" />
    <asp:Button runat="server" id="btnSearch" text="Search" OnClientClick="validateSearch()" />
</asp:Panel>
<br />
<br />
<asp:Panel ID="pnlUpload" runat="server" style="visibility:hidden;">
<asp:FileUpload ID="fileUpload" runat="server" />
       <asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="btnUpload_Click" OnClientClick="validateUpload()"  />
<asp:RequiredFieldValidator ID="reqFileUpload" runat="server" ControlToValidate="fileUpload" ErrorMessage="File Required!" />
</asp:Panel>


C#
<script type="text/javascript">
    function validateSearch()
    {
    var searchTxt = document.getElementById('tbxSearch').value ;

    if(searchTxt != '')
    {
document.getElementById('pnlUpload').style.visibility="visible";
    return true;
    }
    else
    return false;
    }
    function validateUpload()
    {
    if(document.getElementById("fileUpload").value != "" && document.getElementById('tbxSearch').value != "")
    {
   return true;
}
else
return false;

    }
    </script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900