views:

573

answers:

1

So I have a LinkButton called linkButton.

    protected LinkButton linkButton;

and inside a loop which gets every directory of a specified directory, I have this:

    linkButton = new LinkButton();
    linkButton.Text = DirInf.Name;
    linkButton.CommandArgument = DirInf.FullName;
    linkButton.Command += new CommandEventHandler(linkButton_Command);

Where DirInf is of type DirectoryInfo.

Now when I put:

        Response.Redirect("filebrowser.aspx?dir=" + linkButton.CommandArgument);
        linkButton = new LinkButton();

inside the function linkButton_Command, linkButton.CommandArgument seems to always be "C:\Windows," which so happens to be the last value linkButton.CommandArgument was assigned.

But I created a new instance of it - but the value still retains...

I'm quite puzzled...

A: 

Response.Redirect will throw a ThreadAbortException, so your assignment is never actually taking place. I'm curious as to when you were testing the value again as well, given the way that ASP.NET state works... was it on the next request?

I admit to being somewhat confused as to what you're actually doing. Could you provide a short but complete example (page + codebehind) which demonstrates the problem?

Jon Skeet
Well basically its a ASP.NET page which has a table, and in the codebehind page, it basically just calls a function, which calls another function which lists through every directory, and lists them.The problem is that when I add a linkButton in the Name Column, the linkButton doesn't seem to "refresh" CommandArgument, even when I click on the first/second/any item, it redirects to the last item's CommandArgument. This shouldn't be happening - as I'm creating a new instance every loop...but it seems to be - so...thats why I'm puzzled