单击按钮时页面不刷新

时间:2013-10-03 12:11:17

标签: c# asp.net button webpage

在我的项目中,有多个页面继承了相同的母版页,并且除了1或2页之外都响应,所有代码都没有变化。 我在按钮单击按钮上插入断点无效。 我该如何检查问题。 请帮忙

以下是我的网页代码

<%@ Page Title="Product Stock" Language="C#" MasterPageFile="~/admin/AdminMaster.master" AutoEventWireup="true" CodeFile="ProductStock.aspx.cs" Inherits="admin_ProductStock" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .auto-style3 {
            width: 259px;
        }
        .auto-style4 {
            width: 479px;
        }
        .auto-style5 {
            height: 65px;
        }
        .auto-style6 {
            width: 479px;
            height: 65px;
        }
        .auto-style7 {
            height: 74px;
        }
        .auto-style8 {
            width: 479px;
            height: 74px;
        }
        .auto-style9 {
            width: 69px;
        }
        .auto-style10 {
            height: 74px;
            width: 68px;
        }
        .auto-style11 {
            height: 65px;
            width: 68px;
        }
        .auto-style12 {
            width: 68px;
        }
        .auto-style13 {
            width: 451px;
        }
        .auto-style14 {
            width: 451px;
            height: 74px;
        }
        .auto-style15 {
            width: 451px;
            height: 65px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" runat="server" contentplaceholderid="ContentPlaceHolder1">
    <table style="width:100%;">
        <tr>
            <td>
                <asp:Image ID="Image1" runat="server" Height="123px" ImageUrl="~/admin/images/insert.jpg" Width="158px" />
            </td>
            <td class="auto-style4">
                <asp:Label ID="lblinsertion" runat="server" BackColor="#FFFF66" Font-Bold="True" Font-Italic="True" Font-Names="Euphemia" Font-Size="XX-Large" Font-Underline="True" ForeColor="#009900" Text="Insert Product Stock Information"></asp:Label>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </td>
            <td class="auto-style12">&nbsp;</td>
        </tr>
        <tr>
            <td class="auto-style5">
                <asp:Label ID="lblproductname" runat="server" Text="Product Name" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
            <td class="auto-style6">
                <asp:DropDownList ID="ddlprdctname" runat="server" Width="235px" ValidationGroup="vg1"></asp:DropDownList>
            </td>
            <td class="auto-style11">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="ddlprdctname" ErrorMessage="Select Product Name" ValidationGroup="vg1"></asp:RequiredFieldValidator>
            </td>
        </tr>

        <tr>
            <td>
                <asp:Label ID="lblquantity" runat="server" Text="Quantity" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
            <td class="auto-style4">
                <asp:TextBox ID="txtquantity" runat="server" Width="235px" ValidationGroup="vg1"></asp:TextBox>
            </td>
            <td class="auto-style12">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="txtquantity" ErrorMessage="Enter Quantity" ValidationGroup="vg1"></asp:RequiredFieldValidator>
            </td>
        </tr>

        <tr>
            <td>
                <asp:Label ID="lblstocktype" runat="server" Text="Stock Type" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
            <td class="auto-style4">
                <asp:DropDownList ID="ddlstocktype" runat="server" Width="235px" Height="42px" ValidationGroup="vg1"></asp:DropDownList>
            </td>
            <td class="auto-style12">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ControlToValidate="ddlstocktype" ErrorMessage="Please Enter Stock Type" ValidationGroup="vg1"></asp:RequiredFieldValidator>
            </td>
        </tr>

        <tr>
            <td>
                <asp:Label ID="lblstockdate" runat="server" Text="Stock Date" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
            <td class="auto-style4">
                <asp:TextBox ID="txtstockdate" runat="server" ValidationGroup="vg1"  Height="55px" Width="235px"></asp:TextBox>
            </td>
            <td class="auto-style12">
                <asp:Label ID="lbldateformat" runat="server" Text="dd/mm/yy"></asp:Label>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtstockdate" ErrorMessage="Please Enter Stock Date" ValidationGroup="vg1"></asp:RequiredFieldValidator>
            </td>
        </tr>

        <tr>
            <td class="auto-style3"></td>
            <td class="auto-style4">
                <asp:Button ID="btnInsert" runat="server" Text="Insert" Width="125px" ValidationGroup="vg1" OnClick="btnInsert_Click" />            
            </td>
            <td>
                <asp:Button ID="check" runat="server" Text="Lets Check" />
            </td>
            <td class="auto-style12">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="3">
                <asp:Label ID="lblmsg" runat="server" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
        </tr>
    </table>
</asp:Content>

<asp:Content ID="Content3" runat="server" contentplaceholderid="ContentPlaceHolder2">
    <asp:Panel ID="ViewPanel" runat="server">
      <table style="width:100%;">
            <tr>
                <td class="auto-style3">
                    <asp:Image ID="Image2" runat="server" Height="100px" ImageUrl="~/admin/images/view.jpg" Width="133px" />
                </td>
                <td>
                    <asp:Label ID="Label1" runat="server" BackColor="Yellow" Font-Bold="True" Font-Italic="True" Font-Names="Euphemia" Font-Size="XX-Large" Font-Underline="True" ForeColor="#009900" Text="View All Information"></asp:Label>
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>
     <asp:GridView ID="gridview" AutoGenerateColumns="false" runat="server" style="margin-left: 0px" AllowPaging="True" AllowSorting="True" CellPadding="3" Height="238px"  BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="Solid" BorderWidth="1px" CellSpacing="2" OnRowCommand="gridview_RowCommand" OnPageIndexChanging="gridview_PageIndexChanging">
        <Columns>
            <asp:BoundField HeaderText="Stock ID" DataField="StockID" />
            <asp:BoundField HeaderText="Product Name" DataField="ProductID" />
            <asp:BoundField HeaderText="Quantity" DataField="Quantity" />
            <asp:BoundField HeaderText="Stock Type" DataField="StockType" />
            <asp:BoundField HeaderText="Stock Date" DataField="StockDate" />

            <asp:TemplateField HeaderText="Delete Record">
                <ItemTemplate>
                    <asp:Button ID="delete" OnClientClick="return confirm('Are You Sure To Delete The Record?')" Text="Delete This Record" CommandName="del" CommandArgument='<%# Eval("StockID") %>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Edit  Record">
                <ItemTemplate>
                    <asp:Button ID="update"  CommandName="upd" Text="Edit this Record" CommandArgument='<%# Eval("StockID") %>' runat="server" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
         <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
         <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
         <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
         <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
         <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
         <SortedAscendingCellStyle BackColor="#FFF1D4" />
         <SortedAscendingHeaderStyle BackColor="#B95C30" />
         <SortedDescendingCellStyle BackColor="#F1E5CE" />
         <SortedDescendingHeaderStyle BackColor="#93451F" />
        </asp:GridView>

    <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
        </asp:Panel>
     <br />

</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
 <asp:Label ID="lblupdate" runat="server" Text="Select the record to be updated" Font-Names="Segoe Print" Font-Size=20></asp:Label>

    <asp:Panel ID="UpdatePanel" runat="server">

 <table style="width:100%;">
        <tr>
            <td>
                <asp:Image ID="Image3" runat="server" Height="123px" ImageUrl="~/admin/images/insert.jpg" Width="158px" />
            </td>
            <td >
                <asp:Label ID="lblupdupdation" runat="server" BackColor="#FFFF66" Font-Bold="True" Font-Italic="True" Font-Names="Euphemia" Font-Size="XX-Large" Font-Underline="True" ForeColor="#009900" Text="Update Product Stock Information"></asp:Label>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            </td>
            <td >&nbsp;</td>
        </tr>
     <tr>
            <td>
                <asp:Label ID="lblupdstockid" runat="server" Text="Quantity" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="txtupdstockid" runat="server" ReadOnly="true" Width="235px"></asp:TextBox>
            </td>
            </tr>
        <tr>
            <td >
                <asp:Label ID="lblupdproductname" runat="server" Text="Product Name" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
            <td >
                <asp:DropDownList ID="ddlupdprdctname" runat="server" Width="235px"></asp:DropDownList>
            </td>
            <td >
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ddlupdprdctname" ErrorMessage="Enter Product Name"></asp:RequiredFieldValidator>
            </td>
        </tr>

        <tr>
            <td>
                <asp:Label ID="lblupdquantity" runat="server" Text="Quantity" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="txtupdquantity" runat="server" Width="235px"></asp:TextBox>
            </td>
            <td >
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtupdquantity" ErrorMessage="Enter Quantity"></asp:RequiredFieldValidator>
            </td>
        </tr>

        <tr>
            <td>
                <asp:Label ID="lblupdstocktype" runat="server" Text="Stock Type" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
            <td >
                <asp:DropDownList ID="ddlupdstocktype" runat="server" Width="235px"></asp:DropDownList>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="ddlupdstocktype" ErrorMessage="Please Enter Stock Type"></asp:RequiredFieldValidator>
            </td>
        </tr>

        <tr>
            <td>
                <asp:Label ID="lblupdstockdate" runat="server" Text="Stock Date" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="txtupdstockdate" runat="server" ValidationGroup="vg1"  Height="16px" Width="235px"></asp:TextBox>
            </td>
            <td >
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtupdstockdate" ErrorMessage="Please Enter Stock Date" ValidationGroup="vg1"></asp:RequiredFieldValidator>
            </td>
        </tr>

        <tr>
            <td></td>
            <td >
                <asp:Button ID="btnUpdate" runat="server" Text="Update" Width="125px" ValidationGroup="vg1" OnClick="btnUpdate_Click" />
            </td>
            <td >&nbsp;</td>
        </tr>
        <tr>
            <td colspan="3">
                <asp:Label ID="lblupdmsg" runat="server" Font-Bold="True" Font-Italic="True" Font-Size="Medium"></asp:Label>
            </td>
        </tr>
    </table>

    </asp:Panel>
</asp:Content>

我的按钮

的客户端代码
 protected void btnInsert_Click(object sender, EventArgs e)
    {
        try
        {
        int  productID, quantity;
        string stockType;
        DateTime stockDate;

        productID = int.Parse(ddlprdctname.SelectedValue);
        quantity = int.Parse(txtquantity.Text.Trim());
        stockType = ddlstocktype.SelectedValue.ToString().Trim();
        stockDate = DateTime.Parse(txtstockdate.Text.Trim());
        ProductStock prdctstock = new ProductStock();
        prdctstock.ProductID = productID;
        prdctstock.Quantity = quantity;
        prdctstock.StockType = stockType;
        prdctstock.StockDate = stockDate;
         if (new InsertAction().InsertData(prdctstock))
                {
                    lblmsg.Text = "Inserted Sucessfully";
                    ViewPanel.Visible = true;
                }
                else
                {
                    lblmsg.Text = "Please Check all the fields";
                }

            BindGridView();
            ProductInfo prdctinfo = new ProductInfo();
            if (stockType == "In")
            {
                prdctinfo.Quantity += quantity;
            }
            if (stockType == "Out")
            {
                prdctinfo.Quantity -= quantity;
            }
            }

             catch (Exception ex)
        {
            if (ex is FormatException)
            {
                 lblmsg.Text = "Character value are not allowed";
            }
            else
            {
                lblmsg.Text = ex.Message;

            }
        }


    }

2 个答案:

答案 0 :(得分:0)

将断点放在命中的位置。查看调用堆栈,并在找到原因而不是要触发的方法时跳到这一点。 没有更多信息,做不了多少。 希望这有帮助

答案 1 :(得分:0)

我看到了一些不需要的代码

1)请删除所有asp.net控件中的ValidationGroup="vg1"除按钮。

2)不要使用面板,有时按钮点击不能使用面板控件,所以请使用表而不是面板。(或删除asp:面板控件)

3)并且必须检查与服务器端相同的按钮点击事件。

4)如果你给我我们的服务器端代码,那么我会回复你!!

相关问题