Click here to Skip to main content
15,936,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have to store click status as "clicked" after use it as in if block in edit row but the value setting null

public string btnStatus;

private void bindSearchResult()
 btnStatus = "clicked";
lblMessage.Text = btnStatus; // lable is displaying fine 
protected void gvMainCategory_RowCommand(object sender, GridViewCommandEventArgs e)
if (e.CommandName == "EditRow")
                int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                gvMainCategory.EditIndex = rowIndex;
                if (btnStatus == "clicked") // if btnstatus is null due to this it goes to else
Updated 17-Jan-16 0:18am

1 solution

An ASP.NET page lives as long as the request fulfilled...After that it destroyed and a very new page will be created for the next request, with all the variables initialized to default values...
So on every postback (on click event) you are dealing with a new instance of the page and so all the variables are initialize to default values... btnStatus to null fro your case...
This behavior is a result of the disconnected nature of the web...
You have some options of course to handle 'real' global variables...
1. Store it on the session/application level
2. Attach it to the object initiated the click event (the grid row in your case) and store it in the View State...
Share this answer
Sergey Alexandrovich Kryukov 17-Jan-16 13:12pm    
My 5, but I would also explained that the object has to be serializeable.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900