Click here to Skip to main content
15,905,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="SalesOrder.aspx.cs" Inherits="SalesOrder" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

    <script type="text/javascript" language="javascript">
        function GetTotal() {
            var val1 = document.getElementById('<%=txtq.ClientID%>').value;
            var val2 = document.getElementById('<%=txtp.ClientID%>').value;
            if (val1 != "" && val2 != "") {
                document.getElementById('<%=txttotal.ClientID%>').value = val1 * val2;
            }

        }

    </script>

    <style type="text/css">
        .style9 {
            height: 34px;
        }
    </style>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
    <asp:Panel ID="Panel1" runat="server">
        <br />
        <asp:HyperLink ID="HyperLink12" runat="server" NavigateUrl="~/Customer.aspx">Customer Details</asp:HyperLink>
        <br />
        <br />
        <br />
        <asp:HyperLink ID="HyperLink13" runat="server" NavigateUrl="~/SalesOrder.aspx">Sales Order</asp:HyperLink>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
    </asp:Panel>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

    <table>

<tr>
<td align="right">Customer ID</td>
<td>
    <asp:DropDownList ID="ddlcid" runat="server" DataSourceID="SqlDataSource1"
        DataTextField="Customer_Id" DataValueField="Customer_Id" AppendDataBoundItems="true">
        <asp:ListItem>---select Customer id---</asp:ListItem>
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:sqlserverConnectionString %>"
        SelectCommand="SELECT [Customer_Id] FROM [CustomerTable_]">
    </asp:SqlDataSource>
    </td>
</tr>
<tr>
<td align="right">Product Id</td>
<td>
    <asp:DropDownList ID="ddlpid" runat="server" DataSourceID="SqlDataSource2"
        DataTextField="Productcode" DataValueField="Productcode"
        AppendDataBoundItems="true"
        onselectedindexchanged="ddlpid_SelectedIndexChanged" AutoPostBack="True">
        <asp:ListItem>---select Product Id---</asp:ListItem>
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
        ConnectionString="<%$ ConnectionStrings:sqlserverConnectionString %>"
        SelectCommand="SELECT [Productcode] FROM [Products]"></asp:SqlDataSource>
    </td>
</tr>
<tr>
<td align="right">Price</td>
<td>
    <asp:TextBox ID="txtp" runat="server"></asp:TextBox>
    </td>
</tr>
<tr>
<td align="right">Quantity</td>
<td>
    <asp:TextBox ID="txtq" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ErrorMessage="*" ForeColor="Red" ControlToValidate="txtq"></asp:RequiredFieldValidator>
    </td>
</tr>

<tr>
<td align="right" class="style9">Total</td>
<td class="style9">
    <asp:TextBox ID="txttotal" runat="server"></asp:TextBox>
    <asp:Button ID="add" runat="server" Text="add" OnClientClick="return GetTotal();" />
&nbsp;</td>
</tr>
<tr>
<td align="right">Date Of Delivery</td>
<td>

    <asp:TextBox ID="txtdate" runat="server"></asp:TextBox>
  <asp:CalendarExtender ID="calender1" runat="server" TargetControlID="txtdate"
        Format="dd/MM/yyyy"></asp:CalendarExtender>


    </td>
</tr>
<tr>
<td colspan="2" align="center">

    <asp:Button ID="btnsubmit" runat="server" Text="Submit"
        onclick="btnsubmit_Click" />

</td>
</tr>
</table>

</asp:Content>
Posted
Comments
member1431 3-May-14 3:15am    
use required field validator and validation summary

1 solution

Hi,
You can use CustomValidator which will allow you to check condition in code behind,
Please refer below links, and let me know if it helps,
http://www.w3schools.com/aspnet/showaspx.asp?filename=demo_customvalidator[^]
http://www.codingfusion.com/Post/CustomValidator-Example-in-asp-net[^]
Thanks,
Hitesh Varde
 
Share this answer
 
Comments
v.latha 3-May-14 3:47am    
I have two tables products table and sales order table
when I insert the data in sales order in the page if the quantity is doesnot exist in products i want to show error message
Hitesh Varde 3-May-14 5:12am    
you have to check condition in code behind event raised by CustomValidator Control.
v.latha 5-May-14 5:19am    
yes I got the 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