1个2更新面板未更新(相同代码)和字符串未设置

时间:2013-04-29 11:39:10

标签: c# asp.net updatepanel

我试图在我的代码隐藏中设置一个公共字符串,只需单击一个按钮,然后再针对新值运行一个函数,但该值未设置。另外我的updatepanel“upTables”不起作用,它引用了页面,但是我的更新面板“upForm”工作并且没有刷新页面,我也设置了两个面板,请看下面的代码

为了便于阅读,我已将其修剪下来,

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

由于

form.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>

form.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)
    {

    }
}

1 个答案:

答案 0 :(得分:0)

对它进行排序!

        smEquipment.RegisterAsyncPostBackControl(butUsers);