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. Clarification On Static Member [modified]

Clarification On Static Member [modified]

Scheduled Pinned Locked Moved ASP.NET
databasesysadminhelpquestion
6 Posts 3 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.
  • R Offline
    R Offline
    Rahul83
    wrote on last edited by
    #1

    Hi friends..plz go through this pseudo code I Included Requirid Namespaces Dataset ds;--------------------------------------1 //static Dataset ds;-----------------------------2 protected void page_load(parameters) { ds = function in Data acesss Layer which retrives records from database and returns dataset. populatedatagrid(); } void populatedatagrid() { if(mydropdownlist.selectedIndex=0) datagrid1.datasource=ds; else { datagrid1.Datasource= here I performed filtering action using Row Filter Property and selected Index Value } } void mydropdownlist_selectedIndexchanged(parameters) { populatedatagrid(); } I am designing a web page where by default all records will displayed.but by selecting from dropdownlist I can filter the records.Later I thought its not right to perform the fuctionalities of the page_load event at each postback(unnecessry making connection to the database)..so i used Page.Ispostback to avoid that..so first time it worked fine but when i selected from dropdwn list it throws an error "object reference not set to an instance of object".. reason for above error i understood(because in page load event i am returning dataset which does not happened at page post back)..so one of my friend commented the line no-1 and uncommented the line no-2 in above code..thus made dataset static..and it works What I am not understanding is why making the dataset static solved the task..though HTTP is static?Is making dataset ststic makes the records to be saved at server? Warm Regards, Rahul Agarwal -- modified at 7:11 Tuesday 12th June, 2007

    R A 3 Replies Last reply
    0
    • R Rahul83

      Hi friends..plz go through this pseudo code I Included Requirid Namespaces Dataset ds;--------------------------------------1 //static Dataset ds;-----------------------------2 protected void page_load(parameters) { ds = function in Data acesss Layer which retrives records from database and returns dataset. populatedatagrid(); } void populatedatagrid() { if(mydropdownlist.selectedIndex=0) datagrid1.datasource=ds; else { datagrid1.Datasource= here I performed filtering action using Row Filter Property and selected Index Value } } void mydropdownlist_selectedIndexchanged(parameters) { populatedatagrid(); } I am designing a web page where by default all records will displayed.but by selecting from dropdownlist I can filter the records.Later I thought its not right to perform the fuctionalities of the page_load event at each postback(unnecessry making connection to the database)..so i used Page.Ispostback to avoid that..so first time it worked fine but when i selected from dropdwn list it throws an error "object reference not set to an instance of object".. reason for above error i understood(because in page load event i am returning dataset which does not happened at page post back)..so one of my friend commented the line no-1 and uncommented the line no-2 in above code..thus made dataset static..and it works What I am not understanding is why making the dataset static solved the task..though HTTP is static?Is making dataset ststic makes the records to be saved at server? Warm Regards, Rahul Agarwal -- modified at 7:11 Tuesday 12th June, 2007

      R Offline
      R Offline
      rreddy V
      wrote on last edited by
      #2

      change the property of dropdownlist autopostback property to TRUE and try

      1 Reply Last reply
      0
      • R Rahul83

        Hi friends..plz go through this pseudo code I Included Requirid Namespaces Dataset ds;--------------------------------------1 //static Dataset ds;-----------------------------2 protected void page_load(parameters) { ds = function in Data acesss Layer which retrives records from database and returns dataset. populatedatagrid(); } void populatedatagrid() { if(mydropdownlist.selectedIndex=0) datagrid1.datasource=ds; else { datagrid1.Datasource= here I performed filtering action using Row Filter Property and selected Index Value } } void mydropdownlist_selectedIndexchanged(parameters) { populatedatagrid(); } I am designing a web page where by default all records will displayed.but by selecting from dropdownlist I can filter the records.Later I thought its not right to perform the fuctionalities of the page_load event at each postback(unnecessry making connection to the database)..so i used Page.Ispostback to avoid that..so first time it worked fine but when i selected from dropdwn list it throws an error "object reference not set to an instance of object".. reason for above error i understood(because in page load event i am returning dataset which does not happened at page post back)..so one of my friend commented the line no-1 and uncommented the line no-2 in above code..thus made dataset static..and it works What I am not understanding is why making the dataset static solved the task..though HTTP is static?Is making dataset ststic makes the records to be saved at server? Warm Regards, Rahul Agarwal -- modified at 7:11 Tuesday 12th June, 2007

        R Offline
        R Offline
        rreddy V
        wrote on last edited by
        #3

        Change dropdown property autopostback to TRUE

        A 1 Reply Last reply
        0
        • R rreddy V

          Change dropdown property autopostback to TRUE

          A Offline
          A Offline
          Arun Immanuel
          wrote on last edited by
          #4

          Please note that you have an option to modify your message. And what the PostBack property is going to do with the Question?:confused:

          Regards, Arun Kumar.A

          1 Reply Last reply
          0
          • R Rahul83

            Hi friends..plz go through this pseudo code I Included Requirid Namespaces Dataset ds;--------------------------------------1 //static Dataset ds;-----------------------------2 protected void page_load(parameters) { ds = function in Data acesss Layer which retrives records from database and returns dataset. populatedatagrid(); } void populatedatagrid() { if(mydropdownlist.selectedIndex=0) datagrid1.datasource=ds; else { datagrid1.Datasource= here I performed filtering action using Row Filter Property and selected Index Value } } void mydropdownlist_selectedIndexchanged(parameters) { populatedatagrid(); } I am designing a web page where by default all records will displayed.but by selecting from dropdownlist I can filter the records.Later I thought its not right to perform the fuctionalities of the page_load event at each postback(unnecessry making connection to the database)..so i used Page.Ispostback to avoid that..so first time it worked fine but when i selected from dropdwn list it throws an error "object reference not set to an instance of object".. reason for above error i understood(because in page load event i am returning dataset which does not happened at page post back)..so one of my friend commented the line no-1 and uncommented the line no-2 in above code..thus made dataset static..and it works What I am not understanding is why making the dataset static solved the task..though HTTP is static?Is making dataset ststic makes the records to be saved at server? Warm Regards, Rahul Agarwal -- modified at 7:11 Tuesday 12th June, 2007

            A Offline
            A Offline
            Arun Immanuel
            wrote on last edited by
            #5

            Please don't use static unless you are sure that it will not create any side effect. Consider the following program:

            static int i;
            protected void Page_Load(object sender, EventArgs e)
            {
            }
            protected void  Button1_Click(object sender, EventArgs e)
            {
                i=i+1;
                TextBox1.Text=i.ToString();
            }
            

            For each Button Click event, the value of "i" is incremented and displayed in the TextBox. I have clicked the button 5 times and the text box shows 5 in it. At this moment,when I opened another browse , copy - paste the same url and I tried to click the button, it shows "6" in it. So, I think that: For the first request, an Object of the page is created and maintained in the server. For subsequent request separate object is created for the page and is rendered to the Client, and the static member is shared by all objects.

            Regards, Arun Kumar.A

            R 1 Reply Last reply
            0
            • A Arun Immanuel

              Please don't use static unless you are sure that it will not create any side effect. Consider the following program:

              static int i;
              protected void Page_Load(object sender, EventArgs e)
              {
              }
              protected void  Button1_Click(object sender, EventArgs e)
              {
                  i=i+1;
                  TextBox1.Text=i.ToString();
              }
              

              For each Button Click event, the value of "i" is incremented and displayed in the TextBox. I have clicked the button 5 times and the text box shows 5 in it. At this moment,when I opened another browse , copy - paste the same url and I tried to click the button, it shows "6" in it. So, I think that: For the first request, an Object of the page is created and maintained in the server. For subsequent request separate object is created for the page and is rendered to the Client, and the static member is shared by all objects.

              Regards, Arun Kumar.A

              R Offline
              R Offline
              Rahul83
              wrote on last edited by
              #6

              Thanks a lot Arun..u understood my question..and answered precisely..

              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