Welcome to Dream.In.Code
Become an Expert!

Join 149,483 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,379 people online right now. Registration is fast and FREE... Join Now!




linkbutton And session

 
Reply to this topicStart new topic

linkbutton And session, use linkbuttonv for session

royroy7
2 May, 2007 - 08:24 AM
Post #1

New D.I.C Head
*

Joined: 6 Apr, 2007
Posts: 9


My Contributions
my asp code:
CODE
<asp:LinkButton runat="server" Text="Edit" ID="lnk1" PostBackUrl="../Editor/Editor.aspx" OnClick="lnk1_Click"></asp:LinkButton>


my cs code:

CODE
public string Link
    {
        set
        {
            
            lnk1.PostBackUrl += "?ArticalID=" + value;
            lnk1.AccessKey = value;
        }
    }   protected void lnk1_Click(object sender, EventArgs e)
    {
        updateArtSession up = new updateArtSession();
        up.ArtCode = Convert.ToInt32(lnk1.AccessKey);
    }


is there better way to put the value for this session?






--------------------------------------------------------------------------------
Sincerely,
roy
User is offlineProfile CardPM
+Quote Post

JellyBean
RE: Linkbutton And Session
4 May, 2007 - 12:12 AM
Post #2

D.I.C Head
**

Joined: 25 Apr, 2007
Posts: 60


My Contributions
Firstly I see you posted here a while ago, and some kind person already replied,
QUOTE
I am afraind that when you set the PostBackUrl for a LinkButton, the code in the lnk1_Click will never execute, and the value never be stored in the session.


You are using the AccessKey property of the LinkButton AND you are setting the postback url to include your session key value. But you never attempt to use the value posted back in the url.

What are you trying to achieve?

If I want to set up some kind of artificial session id then I use code similar to the following:
CODE
int mySessionId = 0;
if (Session["MySessionId"] == null)
{
   mySessionId = CreateNewSessionId(); // some method to create a session id
   Session["MySessionId"] = mySessionId;
}
else
{
   try
   {
      mySessionId = Convert.ToInt32(Session["MySessionId"]);
   }
   catch (FormatException) { }
}


The whole point of the session is that it is able to store data at the server. The default timeout for a session is 20 minutes I think, so that data will cease to exist after this time.

If you want to store a session id at the client then why not try storing it in the ViewState.

Hope this helps!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 04:40PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month