• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1599
  • Last Modified:

Insert Session value into formview textbox (asp.net vb)


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.

1 Solution
Hi, what you are doing is ok, you just need to add logic to skip assigning value if session is nothing (for vb.net  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
EdAuthor Commented:
Works perfectly, thnaks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now