How can I add an invisible form variable?

Posted on 2008-11-13
Last Modified: 2012-05-05
I have a manual table and I was wondering if there is anyway I can add an invisible form variable or text box. The reason I need it is so I can set it equal to the Title and set that to a session that I can reference throughout the rest of the application. This is the code I have. Any help would be appreciated.

            dtr = Mycomm.ExecuteReader()

            If dtr.HasRows Then

                While dtr.Read()

                    If dtr("Title") = "" And dtr("Description") = "" Then


                        success = "true"

                        vHtml = vHtml & "<TD align=""left""><FONT size=""1"" face=""Verdana""><a href='edit_election.aspx?id=" & dtr("id") & "'>(edit election)</a> "

                        vHtml = vHtml & "| <a href='delete.aspx?eid=" & dtr("id") & "' onClick=""return confirm('All associated items and responses will be deleted with this election. \n Are you sure you wish to delete this election?')"">(delete election)</a> "

                        vHtml = vHtml & "| <a href='item_list.aspx?id=" & dtr("id") & "'>(edit items)</a>"

                        vHtml = vHtml & "| <a href='response_list.aspx?id=" & dtr("id") & "'>(edit responses)</a></FONT></TD>"

                        vTitle = Replace(dtr("Title"), "''", "'")

                        'vBody = Replace(dtr("Body"), "''", "'")

                        vBody = Replace(dtr("Description"), vbCrLf, "<br>")

                        vStart = dtr("StartDate")

                        vEnd = dtr("EndDate")

                        vHtml = vHtml & "<tr>"

                        vHtml = vHtml & "<TD align=""left""><strong><FONT face=""Verdana"" size=""3"">" & vTitle & "</FONT></strong></TD>"

                        vHtml = vHtml & "</tr>"

                        vHtml = vHtml & "<tr colspan =""2"">"

                        vHtml = vHtml & "<TD  align=""left""><FONT face=""Verdana"" size=""1"">Dates Available: " & vStart & "</FONT>&nbsp;-&nbsp;<FONT face=""Verdana"" size=""1"">" & vEnd & "</FONT><br></TD> "

                        'vHtml = vHtml & "<TD align=""left""><FONT face=""Verdana"" size=""1""><asp:TextBox id=""txtTitle"" runat=""server"" Visible=""True"">" & vTitle & "</asp:TextBox></FONT><br></TD>"

                        vHtml = vHtml & "</tr>"

                        vHtml = vHtml & "<TD align=""left""><FONT face=""Verdana"" size=""2"">" & vBody & "</FONT><br><br></TD>"

                        vHtml = vHtml & "</tr>"

                        vHtml = vHtml & "<tr>"

                    End If

                End While


                success = "false"

            End If

            vHtml = vHtml & "<tr bgcolor=""#818EAD""><td colspan='11' align='Right'><FONT face=""Verdana"" size=""1"">&nbsp;</font></td></tr>"

            vHtml = vHtml & "<tr bgcolor=""#FFFFFF"">"

            vHtml = vHtml & "<th colspan=""11"" align=""right"">"

            vHtml = vHtml & "<HR>"

            vHtml = vHtml & "<FONT face=""Verdana"" size=""1"">&nbsp;</FONT>"

            vHtml = vHtml & "</th>"

            vHtml = vHtml & "</table>"


        End Try

Open in new window

Question by:savache27
    LVL 6

    Expert Comment

    Is it VB.NET or ASP.NET?  If it is VB.NET you are looking for a global variable I believe.  If that is the case you can add a variable using the keyword Friend.  I usually have a vb file as part of my project called modGlobals or something of the sort and it looks like this:  (See code below)

    You can access those variables from any place in your project by calling myCaseId, or myUpdateConnStr, etc...

    Module modGlobals
        Friend myCaseId As Int16 = Nothing
        Friend myUpdateConnStr As String = "F00"
        Friend myConnStr As String = Nothing
        Friend myUserId As Int16 = Nothing
        Friend myRecordId As Int32 = Nothing
        Friend myConnStatus As Int16 = 1
    End Module

    Open in new window


    Author Comment

    Well, I'm working in visual studio and building a manual  table, so I guess I'm really using It's basically a datalist of elections and each election has a title. So when I go into the edit page I would like to keep up with the Title and add it to the edit page.
    LVL 6

    Expert Comment

    You can always add a text box and set the visible property to false.  Refer to the value of it using textboxname.text

    You can also leave it visible and set the forecolor and backcolor of the text box to transparent.  

    Or you can just store the information each time as SESSION["Title"]=vTitle so long as you have started a session at the beginning of your application.  

    Author Comment

    Actually, I don't think that will work for what I need because I would still have no way of telling which text box it was when they clicked on the edit since it's in a loop. Do you know anyway I could just add the title into this:

    <a href='edit_election.aspx?id=" & dtr("id") & "'>(edit election)</a>

    Seems like it would be something like this, but I'm just not sure how to add it in.

    <a href='edit_election.aspx?id=" & dtr("id") & "' & "&title= " & vTitle & "  >(edit election)</a>
    LVL 6

    Accepted Solution

    link1.href = "edit_election.aspx?id=" & dtr("id") & "&title=" & vTitle
    <a id = "link1" runat = "server">(edit election)</a>

    Something along those lines should do for you.


    Author Closing Comment

    Thank you so much for your help!! That works perfectly!!!

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 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

    18 Experts available now in Live!

    Get 1:1 Help Now