0

我试图在我的代码隐藏中设置一个公共字符串,然后单击一个按钮,然后针对新值运行一个函数,但该值没有被设置。我的更新面板“upTables”也不起作用,它引用了页面,但是我的更新面板“upForm”工作并且不刷新页面,我也以相同的方式设置了两个面板,请参阅下面的代码

为了便于阅读,我把它剪掉了,

基本上当我点击butusers时,strmode没有设置为Users并且整个页面刷新,当我点击butEdit时不会发生这种情况......

谢谢

表单.aspx

<asp:Content ID="cntMenu" ContentPlaceHolderID="MenuContent" runat="Server">
<asp:ScriptManager ID="smEquipment" runat="server"></asp:ScriptManager>
    <ul class="menu">
        <li class="menu-title">Equpiment</li>
            <asp:LinkButton ID="butUsers" runat="server" OnClick="butUsers_Click">User Workstations</asp:LinkButton>
        </li>
    </ul>
</asp:Content>

<asp:Content ID="cntCenter" ContentPlaceHolderID="CenterContent" runat="Server">
<asp:UpdatePanel ID="upTables" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <table id="table" class="table">
        <thead>
            <tr>
                <th>&nbsp;</th>
                <th>AssetNo</th>
                <th>CPU</th>
                <th>Asset Type</th>
            </tr>
        </thead>
        <tbody>
            <asp:Repeater ID="rptItems" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                            <asp:LinkButton ID="butEdit" runat="server" OnClick="butEdit_Click" CommandArgument='<%# Eval("ID") %>'>Edit</asp:LinkButton>
                        </td>
                        <td><%# Eval("AssetNo") %></td>
                        <td><%# Eval("CPU") %></td>
                        <td><%# Eval("AssetType") %></td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </tbody>
    </table>
    </ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
<asp:Content ID="cntRight" ContentPlaceHolderID="RightContent" runat="Server">
    <asp:UpdatePanel ID="upForm" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <div class="details">
                <asp:HiddenField ID="hidID" runat="server" />
                <asp:HiddenField ID="hidUserID" runat="server" ClientIDMode="Static" />
                <table class="detailsview" cellpadding="0" cellspacing="0">
                    <tr>
                        <td class="td_title_align">Asset No:</td>
                        <td>
                            <asp:TextBox ID="txtAssetNo" runat="server" CssClass="edit_box"></asp:TextBox>
                        </td>
                        <td class="td_title_align">CPU:</td>
                        <td>
                            <asp:TextBox ID="txtCPU" runat="server" CssClass="edit_box"></asp:TextBox>
                        </td>
                        <td class="td_title_align">Asset Type:</td>
                        <td>
                            <asp:TextBox ID="txtAssetType" runat="server" CssClass="edit_box"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

表单.aspx.cs

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

public partial class equipment : System.Web.UI.Page
{
    dsData.tblEquipmentDataTable dtEquipment;
    dsDataTableAdapters.tblEquipmentTableAdapter taEquipment;
    dsData.tblEquipmentDataTable dtEdit;
    public string strMode { get; set; }


    protected void Page_Load(object sender, EventArgs e)
    {
        strMode = "Default";
        dtEquipment = new dsData.tblEquipmentDataTable();
        dtEdit = new dsData.tblEquipmentDataTable();
        taEquipment = new dsDataTableAdapters.tblEquipmentTableAdapter();
    }
    protected void butUsers_Click(object sender, EventArgs e)
    {
        butUsers.CssClass = "highlight";
        strMode = "Users";
        taEquipment.FillbyUser(dtEquipment);
        rptItems.DataSource = dtEquipment;
        rptItems.DataBind();
        upTables.Update();
    }
    protected void butEdit_Click(object sender, EventArgs e)
    {
        ddAssetType.Items.Clear();
        switch (strMode)
        {
            case "Users":
                ddAssetType.Items.Add("Laptop");
                ddAssetType.Items.Add("Workstation");
            break;
        }

        LinkButton btn = (LinkButton)(sender);
        int intID = Convert.ToInt32(btn.CommandArgument);

        taEquipment.FillByRecordID(dtEdit, intID);

        foreach (DataRow dr in dtEdit.Rows)
        {

            //Populate Fields
            hidUserID.Value = dr["UserID"].ToString();
            hidID.Value = dr["ID"].ToString();
            txtAssetNo.Text = dr["AssetNo"].ToString();
            txtCPU.Text = dr["CPU"].ToString();

            ddAssetType.SelectedValue = dr["AssetType"].ToString();

            upForm.Update();
        }

    }

    protected void btnSave_Click(object sender, EventArgs e)
    {

    }
}
4

1 回答 1

0

整理好了!

        smEquipment.RegisterAsyncPostBackControl(butUsers);
于 2013-04-29T13:19:46.080 回答