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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. session value and using that

session value and using that

Scheduled Pinned Locked Moved ASP.NET
databasehelpperformanceannouncement
4 Posts 2 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.
  • N Offline
    N Offline
    netsooz Amir Hamidi
    wrote on last edited by
    #1

    hi people I've created this session in global.asax part of my project in this way:

    Session["news_id"]= null;

    I've used a datalist to load some news titles from database and when you click on that title (Which is a link button) there opens a popup window and reads the desired news. It the click event of mentioned link button I've told that:

    Session["news_id"]= (int)(dataList1.DataKeys[dataList1.SelectedIndex]);

    (I guess that the snippet above is problmatic) Then in the form_load of that popup page after creating the sqlconnection stuff i've made the below commandtext: "select text from news where id='"+Session["news_id"]+"'"; in which text is a field that news is stored and news is the name of my table. What I get as an error is that sometimes on the click event of my link button says : Object not set to its refrence or something and sometimes it says that index was out of range! Plase help me with you solutions. Thanks alot

    Proper Prepration Prevents Poor Performance! h

    G 1 Reply Last reply
    0
    • N netsooz Amir Hamidi

      hi people I've created this session in global.asax part of my project in this way:

      Session["news_id"]= null;

      I've used a datalist to load some news titles from database and when you click on that title (Which is a link button) there opens a popup window and reads the desired news. It the click event of mentioned link button I've told that:

      Session["news_id"]= (int)(dataList1.DataKeys[dataList1.SelectedIndex]);

      (I guess that the snippet above is problmatic) Then in the form_load of that popup page after creating the sqlconnection stuff i've made the below commandtext: "select text from news where id='"+Session["news_id"]+"'"; in which text is a field that news is stored and news is the name of my table. What I get as an error is that sometimes on the click event of my link button says : Object not set to its refrence or something and sometimes it says that index was out of range! Plase help me with you solutions. Thanks alot

      Proper Prepration Prevents Poor Performance! h

      G Offline
      G Offline
      Gaurav K Singh
      wrote on last edited by
      #2

      You are right, i also think the problem with Session["news_id"]= (int)(dataList1.DataKeys[dataList1.SelectedIndex]); First, dataList1.SelectedIndex is start with 0 and i think news_id is start with 1 (Its my guess). This index of control never be similar with your id. you can use response.write to check this problem... You can also use the similar type of things.... BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyField="id" DataMember="DefaultView" DataSourceID="SqlDataSource1" GridLines="Horizontal" UseAccessibleHeader="True" Width="100px"> []]>](<%#DataBinder.Eval(Container.DataItem, ) ]]> SelectCommand="SELECT [id], [title], [name] FROM [table]"> Here you pass news id as query string.

      The miracle is this--the more we share, the more we have.

      N 1 Reply Last reply
      0
      • G Gaurav K Singh

        You are right, i also think the problem with Session["news_id"]= (int)(dataList1.DataKeys[dataList1.SelectedIndex]); First, dataList1.SelectedIndex is start with 0 and i think news_id is start with 1 (Its my guess). This index of control never be similar with your id. you can use response.write to check this problem... You can also use the similar type of things.... BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyField="id" DataMember="DefaultView" DataSourceID="SqlDataSource1" GridLines="Horizontal" UseAccessibleHeader="True" Width="100px"> []]>](<%#DataBinder.Eval(Container.DataItem, ) ]]> SelectCommand="SELECT [id], [title], [name] FROM [table]"> Here you pass news id as query string.

        The miracle is this--the more we share, the more we have.

        N Offline
        N Offline
        netsooz Amir Hamidi
        wrote on last edited by
        #3

        As a matter of fact the result of return is always -1 ! I don't know why. by the way Do you think I can try the title instead of id? I mean I use the string of title to pass to session and ... by the way, since I am kind of new in asp.net please inlight me with the ways you've provided. I have no idea what I should do with them thanks

        Proper Prepration Prevents Poor Performance! h

        G 1 Reply Last reply
        0
        • N netsooz Amir Hamidi

          As a matter of fact the result of return is always -1 ! I don't know why. by the way Do you think I can try the title instead of id? I mean I use the string of title to pass to session and ... by the way, since I am kind of new in asp.net please inlight me with the ways you've provided. I have no idea what I should do with them thanks

          Proper Prepration Prevents Poor Performance! h

          G Offline
          G Offline
          Gaurav K Singh
          wrote on last edited by
          #4

          You can pass anything instead of id which is unique (because every link open a unique page.). you can use javascript window.open() function also to open in pop up. In pop up page you receive the id/title value and based on that value you can show the content in the pop up.

          The miracle is this--the more we share, the more we have.

          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