如何在内容页面中调用Javascript函数。请帮助我。这是我的页面 [英] How Can I Call Javascript Function In Content Page.Please Help Me. This Is My Page

查看:94
本文介绍了如何在内容页面中调用Javascript函数。请帮助我。这是我的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="SalesOrder.aspx.cs" Inherits="SalesOrder" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">


<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
        <br />
        <br />
        <br />
        <asp:HyperLink ID="HyperLink13" runat="server" NavigateUrl="~/SalesOrder.aspx">Sales Order
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
    

<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:SqlDataSource ID="SqlDataSource1" runat="server" 

        ConnectionString="<%$ ConnectionStrings:sqlserverConnectionString %>" 

        SelectCommand="SELECT [Customer_Id] FROM [CustomerTable_]">
    
    </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:SqlDataSource ID="SqlDataSource2" runat="server" 

        ConnectionString="<%$ ConnectionStrings:sqlserverConnectionString %>" 

        SelectCommand="SELECT [Productcode] FROM [Products]">
    </td>
</tr>
<tr>
<td align="right">Price</td>
<td>
    <asp:TextBox ID="txtp" runat="server">
    </td>
</tr>
<tr>
<td align="right">Quantity</td>
<td>
    <asp:TextBox ID="txtq" runat="server">
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 

        ErrorMessage="*" ForeColor="Red" ControlToValidate="txtq">
    </td>
</tr>
<tr>
<td align="right">Total</td>
<td>
    <asp:TextBox ID="txttotal" runat="server">
    <input type="button" name="total" value="add" onclick="GetTotal()" />
    
    
    
    </td>
</tr>
<tr>
<td align="right">Date Of Delivery</td>
<td>
    <asp:TextBox ID="txtdate" runat="server">
   
    <asp:Calendar ID="Calendar1"

        runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" BorderWidth="2px"

        DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" 

        Height="180px" Width="200px" 

        onselectionchanged="Calendar1_SelectionChanged">
        <dayheaderstyle backcolor="#CCCCCC" font-bold="True" font-size="7pt" />
        <nextprevstyle verticalalign="Bottom" />
        <othermonthdaystyle forecolor="#808080" />
        <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />
        <SelectorStyle BackColor="#CCCCCC" />
        <TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />
        <todaydaystyle backcolor="#CCCCCC" forecolor="Black" />
        <weekenddaystyle backcolor="#FFFFCC" />
    
    
    </td>
</tr>
<tr>
<td colspan="2" align="center">

    <asp:Button ID="btnsubmit" runat="server" Text="Submit" 

        onclick="btnsubmit_Click" />

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







using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class SalesOrder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

       // ScriptManager.RegisterClientScriptBlock(this,this.GetType(),"hi","GetTotal()",true);
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        System.DateTime myDate = new System.DateTime();
        myDate = Calendar1.SelectedDate;
        txtdate.Text = myDate.ToString("dd/MM/yyyy");  
    }

   
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=CKRBTECH\\SQLEXPRESS;Initial Catalog=sqlserver;Integrated Security=True");

        SqlCommand cmd = new SqlCommand("insert into Sales_Order(CustomerId,ProductId,Price,Quantity,Total,Date_Of_Deliver)values(@custid,@prodid,@price,@qty,@tot,@date) ", con);
        cmd.Parameters.AddWithValue("@custid", ddlcid.SelectedItem.ToString());
        cmd.Parameters.AddWithValue("@prodid", ddlpid.SelectedItem.ToString());
        cmd.Parameters.AddWithValue("@price", txtp.Text.ToString());
        cmd.Parameters.AddWithValue("@qty", txtq.Text.ToString());
        cmd.Parameters.AddWithValue("@total", txttotal.Text.ToString());
        cmd.Parameters.AddWithValue("@date", txtdate.Text.ToString());
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Write("data inserted successfully");
       
    }

    protected void ddlpid_SelectedIndexChanged(object sender, EventArgs e)
    {
        showdata(ddlpid.SelectedItem.Value);
    }
    private void showdata(string id)
    {
        DataTable dt = new DataTable();
        SqlConnection con = new SqlConnection("Data Source=CKRBTECH\\SQLEXPRESS;Initial Catalog=sqlserver;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("select Price from Products where Productcode=@prodid", con);
        cmd.Parameters.AddWithValue("@prodid", ddlpid.SelectedItem.Value);
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            txtp.Text = dt.Rows[0]["Price"].ToString();
        }


        con.Close();

    }

   
}

推荐答案

ConnectionStrings:sqlserverConnectionString %>\"

SelectCommand=\"SELECT [Customer_Id] FROM [CustomerTable_]\">

</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:SqlDataSource ID=\"SqlDataSource2\" runat=\"server\"

ConnectionString=\"<%
ConnectionStrings:sqlserverConnectionString %>" SelectCommand="SELECT [Customer_Id] FROM [CustomerTable_]"> </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:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%


ConnectionStrings:sqlserverConnectionString %>\"

SelectCommand=\"SELECT [Productcode] FROM [Products]\">
</td>
</tr>
<tr>
<td align=\"right\">Price</td< span class=\"code-keyword\">>
<td>
<asp:TextBox ID=\"txtp\" runat=\"server\">
</td>
</tr>
<tr>
<td align=\"right\">Quantity</td>
<td>
<asp:TextBox ID=\"txtq\" runat=\"server\">
< asp:RequiredFieldValidator ID=\"RequiredFieldValidator1\" runat=\"server\"

ErrorMessage=\"*\" ForeCol or=\"Red\" ControlToValidate=\"txtq\">
</td>
</tr>
<tr>
<td align=\"right\">Total</td>
<td>
<asp:TextBox ID=\"txttotal\" runat=\"server\">
<input type=\"button\" name=\"total\" value=\"add\" onclick=\"GetTotal()\" />



</td>
</tr>
<tr>
<td align=\"right\">Date Of Delivery</td>
<td>
<asp:TextBox ID=\"txtdate\" runat=\"server\">

<asp:Calendar ID=\"Calendar1\"

runat=\"server\" BackColor=\"White\" BorderColor=\"#999999\" Cel lPadding=\"4\" BorderWidth=\"2px\"

DayNameFormat=\"Shortest\" Font-Names=\"Verdana\" Font-Size=\"8pt\" ForeColor=\"Black\"

Height=\"180px\" Width=\"200px\"

onselectionchanged=\"Calendar1_SelectionChanged\">
<dayheaderstyle backcolor=\"#CCCCCC\" font-bold=\"True\" font-size=\"7pt\" />
<nextprevstyle verticalalign=\"Bottom\" />
<othermonthdaystyle forecolor=\"#808080\" />
<SelectedDayStyle BackColor=\"#666666\" Font-Bold=\"True\" ForeColor=\"White\" />
<SelectorStyle BackColor=\"#CCCCCC\" />
<TitleStyle BackColor=\"#999999\" BorderColor=\"Black\" Font-Bold=\"True\" />
<todaydaystyle backcolor=\"#CCCCCC\" forecolor=\"Black\" />
<weekenddaystyle backcolor=\"#FFFFCC\" />


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

<asp:Button ID=\"btnsubmit\" runat=\"server\" Text=\"Submit\"

onclick=\"btnsubmit_Click\" />

</td>
</tr>
</table>
ConnectionStrings:sqlserverConnectionString %>" SelectCommand="SELECT [Productcode] FROM [Products]"> </td> </tr> <tr> <td align="right">Price</td> <td> <asp:TextBox ID="txtp" runat="server"> </td> </tr> <tr> <td align="right">Quantity</td> <td> <asp:TextBox ID="txtq" runat="server"> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ForeColor="Red" ControlToValidate="txtq"> </td> </tr> <tr> <td align="right">Total</td> <td> <asp:TextBox ID="txttotal" runat="server"> <input type="button" name="total" value="add" onclick="GetTotal()" /> </td> </tr> <tr> <td align="right">Date Of Delivery</td> <td> <asp:TextBox ID="txtdate" runat="server"> <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" BorderWidth="2px" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px" onselectionchanged="Calendar1_SelectionChanged"> <dayheaderstyle backcolor="#CCCCCC" font-bold="True" font-size="7pt" /> <nextprevstyle verticalalign="Bottom" /> <othermonthdaystyle forecolor="#808080" /> <SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" /> <SelectorStyle BackColor="#CCCCCC" /> <TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" /> <todaydaystyle backcolor="#CCCCCC" forecolor="Black" /> <weekenddaystyle backcolor="#FFFFCC" /> </td> </tr> <tr> <td colspan="2" align="center"> <asp:Button ID="btnsubmit" runat="server" Text="Submit" onclick="btnsubmit_Click" /> </td> </tr> </table>







using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class SalesOrder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

       // ScriptManager.RegisterClientScriptBlock(this,this.GetType(),"hi","GetTotal()",true);
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        System.DateTime myDate = new System.DateTime();
        myDate = Calendar1.SelectedDate;
        txtdate.Text = myDate.ToString("dd/MM/yyyy");  
    }

   
    protected void btnsubmit_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Data Source=CKRBTECH\\SQLEXPRESS;Initial Catalog=sqlserver;Integrated Security=True");

        SqlCommand cmd = new SqlCommand("insert into Sales_Order(CustomerId,ProductId,Price,Quantity,Total,Date_Of_Deliver)values(@custid,@prodid,@price,@qty,@tot,@date) ", con);
        cmd.Parameters.AddWithValue("@custid", ddlcid.SelectedItem.ToString());
        cmd.Parameters.AddWithValue("@prodid", ddlpid.SelectedItem.ToString());
        cmd.Parameters.AddWithValue("@price", txtp.Text.ToString());
        cmd.Parameters.AddWithValue("@qty", txtq.Text.ToString());
        cmd.Parameters.AddWithValue("@total", txttotal.Text.ToString());
        cmd.Parameters.AddWithValue("@date", txtdate.Text.ToString());
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        Response.Write("data inserted successfully");
       
    }

    protected void ddlpid_SelectedIndexChanged(object sender, EventArgs e)
    {
        showdata(ddlpid.SelectedItem.Value);
    }
    private void showdata(string id)
    {
        DataTable dt = new DataTable();
        SqlConnection con = new SqlConnection("Data Source=CKRBTECH\\SQLEXPRESS;Initial Catalog=sqlserver;Integrated Security=True");
        SqlCommand cmd = new SqlCommand("select Price from Products where Productcode=@prodid", con);
        cmd.Parameters.AddWithValue("@prodid", ddlpid.SelectedItem.Value);
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            txtp.Text = dt.Rows[0]["Price"].ToString();
        }


        con.Close();

    }

   
}


这篇关于如何在内容页面中调用Javascript函数。请帮助我。这是我的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆