Insert Session value into formview textbox  ( vb)

Posted on 2009-02-12
Last Modified: 2013-11-27

I've got a session set called 'Selected date' which I'm trying to add to a textbox in a formview insertitem template.

How do i doi this?

My feeble attemt is

Dim Date2TextBox As TextBox

        FormView1.FindControl("Date2TextBox") = Session("Selecteddate")

 Also if the session is not present then i want the textbox to remain blank and not throw an error.

Question by:edjones1
    LVL 12

    Accepted Solution

    Hi, what you are doing is ok, you just need to add logic to skip assigning value if session is nothing (for  or null for c#).

    Use this code for it:

    I'm using notepad to write this, so please check using intellisense that it is error free.

    Dim tbx As TextBox = CType(FormView1.FindControl("Date2TextBox"), TextBox)

    If Not Session("Selecteddate") is Nothing then

        tbx.text = Session("Selecteddate")
        tbx.text = ""
    end if

    Author Comment

    Works perfectly, thnaks.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now