0

这是我试图通过两个简单的步骤来做的事情:

1)新行(trNewPost),里面有表格,里面有控件来添加新帖子或更新现有帖子。

Default Visible=false;

2)添加按钮使上面的行可见= true;

3) trMyPosts 里面有 Gridview 并显示所有的帖子。

默认可见 = true。

当用户单击编辑 gridview 的任何行(RowCommand 事件)时,我只想隐藏此网格(trMyPosts)并显示 trNewPost。

就这样。事件触发,但没有发生任何事情。

4

1 回答 1

0

我认为你有视图状态问题。

您可以做的其中一件事是:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // do things here
        }
    }

因为每当发生任何事情时,页面都会发回。通过封装你的Page_Loadwith ! Page.IsPostBack,你可以防止这些事情一次又一次地发生。

现在,如果您的变量是全局变量,您将遇到同样的问题。考虑改为使用Session变量。

另外,我只是想向您展示这段代码以防万一:

    protected void HideShowClicked(object sender, EventArgs e)
    {
        // toggle the visibility of the control
        // (that is, if visible then hide, if hidden then show) 
        myControl.Visible = ! myControl.Visible;
    }
于 2011-06-28T18:01:03.247 回答