0

Consider the code

public partial class Classname: somethng
    {   
        bClass objClass = new bClass();
        Boolean isfindclicked=false;
protected void Page_Load(object sender, EventArgs e)
        {
            //rowid = 0;
            if (!IsPostBack)
            {......
              ...
             }
}

  protected void btnFind_Click(object sender, EventArgs e)
        {
         isfindclicked=true;
}

On a button click,certain operations are performed if the isfindclicked value is true.But once the button is clicked the page is reloaded and the value of isfindclicked sets to false.So the fn inside the buttn clicked is not executed...

So any way to make the varible isfindcliked not updated during page postbacks..I ave tried with Session,it worked..but is there any other way out in not updating the isfindclicked value during page reloads...?

David Hoerster
  • 28,421
  • 8
  • 67
  • 102
user1869914
  • 41
  • 1
  • 1
  • 2

1 Answers1

1

Similar to Session (which is a better way IMO), you can also put it in the ViewState.

In btnFind you can do something like this:

 protected void btnFind_Click(object sender, EventArgs e)
 {
     isfindclicked=true;
     ViewState["isFind"] = isfindclicked;
 }

And when you need it:

if (ViewState["isFind"] != null)
    bool found = (bool)ViewState["isFind"];

If wondering about ViewState vs Session here is a nice question about it.

Another option - Save the value inside a Hidden Field

Community
  • 1
  • 1
Blachshma
  • 17,097
  • 4
  • 58
  • 72