c#.net用户点击页面按钮

时间:2017-02-01 22:45:57

标签: c# asp.net user-controls

我有一个带有标签1,2,3的'主页'页面“。我有一个带有表单的usercontrol(child)。当有人点击另一个标签(在页面中)时,我需要用户控件进行回发,这样我就可以保存表单值。

问题是'master'中的控件页面位于错误的viewstate中以回发usercontrol表单。如果我从Page调用usercontrol只有自动发布的后备数据可用。显然,我不想自动回复每个领域。只是很高兴回复来自Page的事件的usercontrol。

我试过从Page调用一个保存按钮,但显然它没有客户端数据 - 它回发空。

'master'页面:Portal.aspx

<%@ Page Trace="true"  Language="C#" AutoEventWireup="true" CodeBehind="Portal.aspx.cs" Inherits="MT2Web.Portal" EnableViewState="true" %>

<form id="form1" runat="server" style="padding: 0px">

           <div class="panel panel-default">
                <div id="Tabs" role="tabpanel">
                    <!-- Nav tabs -->

                    <asp:BulletedList CssClass="nav nav-tabs" ID="userNav"      onclick="userNav_Click" runat="server" DisplayMode="LinkButton"   EnableViewState="False" ViewStateMode="Disabled">
                        <asp:ListItem class="active" Value="0">Login:               </asp:ListItem>

                        <asp:ListItem Value="New">New +</asp:ListItem>

                    </asp:BulletedList>

                </div>
            </div>

 </form>

页面控制器:Portal.aspx.cs

//loads the usercontroller:
Controls.Workflow.Racking Workflow_Racking= (Controls.Workflow.Racking)Page.LoadControl("~/Controls/Workflow/Racking.ascx");

    container.Controls.Add(Workflow_Racking); // note:  dynamically loaded usercontrols usually cant be called by id (Workflow_Racking)

//call a method to the usercontrol to postback



    public void userNav_Click(object sender, BulletedListEventArgs e)
    {
Controls.Workflow.Racking ucRacking = (Controls.Workflow.Racking)Page.LoadControl("~/Controls/Workflow/Racking.ascx");

ucRacking.PartialSave();  //method on UserControl page that i called (didnt work)}
UserControl:  Racking.ascx.cs

    public void PartialSave()
    {
        Validator = new MT2Logic.Validation.RackingValidator();

        Validator.Context.SubmitChanges();
    }

0 个答案:

没有答案