Free State Management ASP component by Biju Francis

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
July 01, 2000
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

Free State Management ASP component

Biju Francis sent ASPFree code that does not use any of the known methods of State management in ASP. What  it is using is a Component which maintains the of Controls and recordsets. This is a very handy component to experiment with!  Thanks Biju! 

<%@ Language=VBScript %>
<object id ='objContainer' progid='DataCom.DataContainer' runat='server'></object>
<%
'Create an Object of Component DataCom.DataContainer

Dim rsData
'----------------------------------------------------------------------------------

'This If Condition Checks if the user is comning from some other page
If trim(Request.QueryString("FromPage"))<>"" then
    'if the user comes from some other page back to this page
    'the values of the controls are retreived
    Set rsData=objContainer.GetControlValues (Session.SessionID ,"Page1Container")
    'Once the Values are Retreived the DataContainer is Killed
    objContainer.KillDataContainer Session.SessionID,"Page1Container"    
End If

'----------------------------------------------------------------------------------

'This function takes one Parameter i.e. the ControlName and
'returns a Value for that Control if it exist.
'This Function is Called below where the Value for the textboxes are
'e.g. value = fnControlValue("txtFirstName")

Function fnControlValue(byval ctrlname)   
    if isobject(rsData) then       
        rsdata.Movefirst
        rsdata.find "ControlName like '" & ctrlname & "'"
        if rsdata.eof then
            fnControlValue = ""
        else
            if isnull(rsdata("ControlValue")) then
                fnControlValue = ""
            else
                fnControlValue = rsData("ControlValue")
            end if
        end if
    else
        fnControlValue = ""        
    end if
End function

'-----------------------------------------------------------------------------------

Response.Write "<html>" _
                & "<body>" _
                & "<Form name ='Page1' method ='Post'>" _
                & "<table border='0' cellpadding='0' width='75%'>" _
                & "<tr>" _
                & "<td colspan='2'><strong>Enter Details</strong></td>" _
                & "</tr>" _
                & "<tr>" _
                & "<td>&nbsp;</td><td>&nbsp;</td>" _
                & "</tr>" _
                & "<tr>" _                
                & "<td>First Name</td><td><input type='text' name='txtFirstName' value ='" & server.HTMLEncode(fnControlValue("txtFirstName")) & "'></td>" _
                & "</tr>" _
                & "<tr><td>Last Name</td><td><input type='text' name='txtLastName' value ='" & server.HTMLEncode(fnControlValue("txtLastName")) & "'></td>" _
                & "</tr>" _
                & "<tr><td>Title</td><td><input type='text' name='txtTitle' value ='" & server.HTMLEncode(fnControlValue("txtTitle")) & "'></td>" _
                & "</tr>" _
                & "<tr><td>Email Id</td><td><input type='text' name='txtEmail' value ='" & fnControlValue("txtEmail") & "'></td>" _
                & "</tr>" _
                & "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>" _
                & "<tr><td></td>" _
                & "<td><input type = 'submit' name = 'cmdSubmit' Value = 'Go to Page2'></td>" _
                & "</tr>" _
                & "</table>" _
                & "</body>" _
                & "</html>"

%>

<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub cmdSubmit_OnClick
    Page1.action = "Page2.asp"
    Page1.submit
End sub

-->
</SCRIPT>

Page 2 of the sample

<%@ language=VBScript %>
<object id ='objContainer' progid='DataCom.DataContainer' runat='server'></object>
<%
'Create an Object of Component DataCom.DataContainer

    Dim rsData
   
    'This Method creates a Container to Store the Control Values
    set rsData = objContainer.CreateDataContainer
    'Loops through the Form Collection
    For each name in Request.Form
        rsData.AddNew
        rsData("ControlName") = name
        rsData("ControlValue") = Request.Form(name)    
    Next
    rsData.UpdateBatch
    'This Method set the Values of the Controls to the Data Container
    objContainer.SetControlValues session.sessionid,"Page1Container",rsData

    Response.Write "<a href='Page1.asp?FromPage=Page2'>Back to Page1</a>"
%>
blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials