Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Help!! Event handler fires everytime I refresh the page!

Help!! Event handler fires everytime I refresh the page!

Scheduled Pinned Locked Moved ASP.NET
designsecurityhelptutoriallearning
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Grapes R Fun
    wrote on last edited by
    #1

    Hello friends Ok, so I was tasked to build this little ‘window’ (I’m speaking enduser ;-) to dynamically add/delete rows containing two values: Role and Deployable. So I thought GridView of course. Also I figured the best way to do this is to create a dataset and store it as session variable, and dynamically bind that sucker to my GridView… below is my ‘example’ code: ********Asp net Page*******

    Doctor Nurse Engineer Teacher Clerk Yes No
    Delete *******Code Behind****** using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; public partial class TEST_testingGridView : System.Web.UI.Page { DataSet ds; DataTable dt; DataRow dr; StringBuilder sb; protected void Page_Load(object sender, EventArgs e) { if (Session["smeRoles"] != null) { GridView2.DataSource = (DataSet)(Session["smeRoles"]); GridView2.DataBind(); } } protected void addButton_C

    P P N D 4 Replies Last reply
    0
    • G Grapes R Fun

      Hello friends Ok, so I was tasked to build this little ‘window’ (I’m speaking enduser ;-) to dynamically add/delete rows containing two values: Role and Deployable. So I thought GridView of course. Also I figured the best way to do this is to create a dataset and store it as session variable, and dynamically bind that sucker to my GridView… below is my ‘example’ code: ********Asp net Page*******

      Doctor Nurse Engineer Teacher Clerk Yes No
      Delete *******Code Behind****** using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; public partial class TEST_testingGridView : System.Web.UI.Page { DataSet ds; DataTable dt; DataRow dr; StringBuilder sb; protected void Page_Load(object sender, EventArgs e) { if (Session["smeRoles"] != null) { GridView2.DataSource = (DataSet)(Session["smeRoles"]); GridView2.DataBind(); } } protected void addButton_C

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      First thing I'd do is put IsPostback in the Page_Load event. Don't bind based on the session.

      the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
      Deja View - the feeling that you've seen this post before.

      1 Reply Last reply
      0
      • G Grapes R Fun

        Hello friends Ok, so I was tasked to build this little ‘window’ (I’m speaking enduser ;-) to dynamically add/delete rows containing two values: Role and Deployable. So I thought GridView of course. Also I figured the best way to do this is to create a dataset and store it as session variable, and dynamically bind that sucker to my GridView… below is my ‘example’ code: ********Asp net Page*******

        Doctor Nurse Engineer Teacher Clerk Yes No
        Delete *******Code Behind****** using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; public partial class TEST_testingGridView : System.Web.UI.Page { DataSet ds; DataTable dt; DataRow dr; StringBuilder sb; protected void Page_Load(object sender, EventArgs e) { if (Session["smeRoles"] != null) { GridView2.DataSource = (DataSet)(Session["smeRoles"]); GridView2.DataBind(); } } protected void addButton_C

        P Offline
        P Offline
        Paszt
        wrote on last edited by
        #3

        I'm going to guess that the event handler for the addRoles button (or is it addButton Button?) fires when you refresh the page only if you press the button before refreshing the page (meaning on the previous page view, the button was pressed). If this is correct: This is a common problem for page developers. When you hit refresh, the posted data is posted back; that posted data contained information telling the page to execute the button's event handler so when you hit refresh the event will be fired again. There are several ways to overcome this, the simplest being to check the datasource to see if the data being inserted is already in the datasource, if not insert it, if so don't insert it.

        G 1 Reply Last reply
        0
        • P Paszt

          I'm going to guess that the event handler for the addRoles button (or is it addButton Button?) fires when you refresh the page only if you press the button before refreshing the page (meaning on the previous page view, the button was pressed). If this is correct: This is a common problem for page developers. When you hit refresh, the posted data is posted back; that posted data contained information telling the page to execute the button's event handler so when you hit refresh the event will be fired again. There are several ways to overcome this, the simplest being to check the datasource to see if the data being inserted is already in the datasource, if not insert it, if so don't insert it.

          G Offline
          G Offline
          Grapes R Fun
          wrote on last edited by
          #4

          Thanks Paszat :-) Although, I have to say, when I trigger some other event handler and then refresh the page data persists. But anyways- I will give your solution a try. Thanks again.

          Nila

          1 Reply Last reply
          0
          • G Grapes R Fun

            Hello friends Ok, so I was tasked to build this little ‘window’ (I’m speaking enduser ;-) to dynamically add/delete rows containing two values: Role and Deployable. So I thought GridView of course. Also I figured the best way to do this is to create a dataset and store it as session variable, and dynamically bind that sucker to my GridView… below is my ‘example’ code: ********Asp net Page*******

            Doctor Nurse Engineer Teacher Clerk Yes No
            Delete *******Code Behind****** using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; public partial class TEST_testingGridView : System.Web.UI.Page { DataSet ds; DataTable dt; DataRow dr; StringBuilder sb; protected void Page_Load(object sender, EventArgs e) { if (Session["smeRoles"] != null) { GridView2.DataSource = (DataSet)(Session["smeRoles"]); GridView2.DataBind(); } } protected void addButton_C

            N Offline
            N Offline
            nagendra rao s v
            wrote on last edited by
            #5

            Hi, I feel you are Missing some thing else. By Default any Event will not fire unless it is called implicitly. Here i want some info from you whether you debugged this with break points if so which event is called first?.

            G 1 Reply Last reply
            0
            • G Grapes R Fun

              Hello friends Ok, so I was tasked to build this little ‘window’ (I’m speaking enduser ;-) to dynamically add/delete rows containing two values: Role and Deployable. So I thought GridView of course. Also I figured the best way to do this is to create a dataset and store it as session variable, and dynamically bind that sucker to my GridView… below is my ‘example’ code: ********Asp net Page*******

              Doctor Nurse Engineer Teacher Clerk Yes No
              Delete *******Code Behind****** using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; public partial class TEST_testingGridView : System.Web.UI.Page { DataSet ds; DataTable dt; DataRow dr; StringBuilder sb; protected void Page_Load(object sender, EventArgs e) { if (Session["smeRoles"] != null) { GridView2.DataSource = (DataSet)(Session["smeRoles"]); GridView2.DataBind(); } } protected void addButton_C

              D Offline
              D Offline
              Deepak the Cool
              wrote on last edited by
              #6

              just put and change according to ur need following code into public partial class { private bool _refreshState; //define bool type variable which return to Refresh state in Internet Explorer private bool _isRefresh; //define bool type variable which return wheather Refresh click or not in Internet Explorer public bool IsRefresh // { get { return _isRefresh;//get the value of Refresh click from Internet Explorer } } protected override object SaveViewState() { Session["_ISREFRESH"] = _refreshState; //define Session variable and intilize object[] allstates = new object[2]; // Define object array named allstates allstates[0] = base.SaveViewState(); //get the base.SaveViewState in allstate array at 0 position allstates[1] = !_refreshState; //get the allstate array at 1 position from !_refreshState return allstates; } protected override void LoadViewState(object savedState)//function for LoadViewState { try { object[] allstates = (object[])savedState; //Parsing saveState value at allsataes object array base.LoadViewState(allstates[0]); //Loading viewState value _refreshState = (bool)allstates[1]; _isRefresh = _refreshState == (bool)Session["_ISREFRESH"]; } catch (Exception e) { } } } and which event is called thru Refresh just put flowwowing code into if (_isRefresh == false) { your code for event is here } hope tht'll helps u :)

              Deepak Smile a Lots,Its Costs Nothing

              G 1 Reply Last reply
              0
              • D Deepak the Cool

                just put and change according to ur need following code into public partial class { private bool _refreshState; //define bool type variable which return to Refresh state in Internet Explorer private bool _isRefresh; //define bool type variable which return wheather Refresh click or not in Internet Explorer public bool IsRefresh // { get { return _isRefresh;//get the value of Refresh click from Internet Explorer } } protected override object SaveViewState() { Session["_ISREFRESH"] = _refreshState; //define Session variable and intilize object[] allstates = new object[2]; // Define object array named allstates allstates[0] = base.SaveViewState(); //get the base.SaveViewState in allstate array at 0 position allstates[1] = !_refreshState; //get the allstate array at 1 position from !_refreshState return allstates; } protected override void LoadViewState(object savedState)//function for LoadViewState { try { object[] allstates = (object[])savedState; //Parsing saveState value at allsataes object array base.LoadViewState(allstates[0]); //Loading viewState value _refreshState = (bool)allstates[1]; _isRefresh = _refreshState == (bool)Session["_ISREFRESH"]; } catch (Exception e) { } } } and which event is called thru Refresh just put flowwowing code into if (_isRefresh == false) { your code for event is here } hope tht'll helps u :)

                Deepak Smile a Lots,Its Costs Nothing

                G Offline
                G Offline
                Grapes R Fun
                wrote on last edited by
                #7

                Thanks Deepak! There has got to be a bug in this, because the button click event fires all on its own when I refresh the page... so I finally decided to create a small private method that checks to see whether or not events in the button click would 'quilify' to be executed - very similar to your approach. Thanks again, don't know what I would do without all you guys' help and support!!!!

                Nila

                1 Reply Last reply
                0
                • N nagendra rao s v

                  Hi, I feel you are Missing some thing else. By Default any Event will not fire unless it is called implicitly. Here i want some info from you whether you debugged this with break points if so which event is called first?.

                  G Offline
                  G Offline
                  Grapes R Fun
                  wrote on last edited by
                  #8

                  Nagendra, Thanks for the debug tip. After stepping into the code, I saw that the button click event fires again when I refresh the page... very frustrating!! So to remedy it as quickly as possible, I created a small method that would check to see if the button click event would 'quilify' to be fired given user's input. I just don't have the time to investigate this silliness- need to keep the boss happy ;P Thanks again!

                  Nila

                  N 1 Reply Last reply
                  0
                  • G Grapes R Fun

                    Nagendra, Thanks for the debug tip. After stepping into the code, I saw that the button click event fires again when I refresh the page... very frustrating!! So to remedy it as quickly as possible, I created a small method that would check to see if the button click event would 'quilify' to be fired given user's input. I just don't have the time to investigate this silliness- need to keep the boss happy ;P Thanks again!

                    Nila

                    N Offline
                    N Offline
                    nagendra rao s v
                    wrote on last edited by
                    #9

                    Hai, That is a Good Method of Making your self Comfortable in Office. But you try it later and you can come across some good concepts in that area. and if possible send me that page complete as an attachment to nagendrarao@glowtouch.com.

                    G 1 Reply Last reply
                    0
                    • N nagendra rao s v

                      Hai, That is a Good Method of Making your self Comfortable in Office. But you try it later and you can come across some good concepts in that area. and if possible send me that page complete as an attachment to nagendrarao@glowtouch.com.

                      G Offline
                      G Offline
                      Grapes R Fun
                      wrote on last edited by
                      #10

                      It's not about making myself comfortable; Im just trying to remedy this and move on- there is lots of pressure when you develop for an emergency operations type group. And I agree with you on finding out exactly WHY sometimes things behave the way they do :-) But now is not the time for that, maybe later. Let me do a couple of things, and then I will send you the code. Thanks again!

                      Nila

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups