开发者

Gridview Rowcommand event firing but show hide controls including Gridview not happening

开发者 https://www.devze.com 2023-03-16 03:09 出处:网络
Here is what I am trying to do in two simple s开发者_开发技巧teps: 1) New Row (trNewPost) which has table inside and controls in it to add new post or to update existing post.

Here is what I am trying to do in two simple s开发者_开发技巧teps:

1) New Row (trNewPost) which has table inside and controls in it to add new post or to update existing post.

Default Visible=false;

2) Add Button to make above row visible = true;

3) trMyPosts has Gridview in it and displays all the posts.

Default visible = true.

When user click on editing any row of the gridview (RowCommand event) I just want to hide this grid (trMyPosts) and show trNewPost.

That's all. events firing, but nothing happening.


I think you've got viewstate problem.

One of the things you can do is this :

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

Because whenever anything happens, the page posts back. By encapsulating your Page_Load with ! Page.IsPostBack, you prevent those things from happening over and over again.

Now, if your variable is a global variable, you will have this same problem. Consider instead using a Session variable.

Also, I just wanted to show you this piece of code just in case :

    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;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消