您的位置:首页精文荟萃软件资讯 → 使用隐藏form把数据从客户端传到服务端

使用隐藏form把数据从客户端传到服务端

时间:2004/10/7 19:05:00来源:本站整理作者:蓝点我要评论(0)


            
             
              
             
            

               
               

            



            源程序下载在本站的源程序栏的html一代类型里,名为隐藏窗体的应用例子

Using hidden forms to transfer data from client side to Server side and vice-versa

Author: Sudhakar M
Level of Difficulty: Beginner
Languages covered: ASP, JavaScript
Pre-required reading: None
Date: Apr 19, 2000


Introduction

This paper discusses how to use hidden forms to transfer data from client side to server-side and vice-
versa. This approach is needed when you have an ASP application, with the individual pages dealing with
only a part of the whole data involved, but at a later time, such as exiting the application, all of the
data entered intermediately so far is needed.

One obvious approach is to use Session variables. Session variables need cookies to be enabled to work.
But what if cookies are disabled? Also in today's e-commerce applications there are scenarios where random
servers service the browser requests depending on the load (load-balanced), so there is no session
involved. This is an alternative approach to session variables and cookies.

The Approach

I will discuss the approach by a simple example. Suppose I have an ASP application with three pages
Name.asp, Address.asp, database.asp. The user navigates from one page to another page entering the
information along the way in the first two pages. Also after the information is entered in each particular
page, the server side needs the information, to make some decisions, like to pull some more data out of a
database based on the entered values and send it to the next page. This process continues until the user
reaches the last page, when all of the previous data is committed to the database. The trickiest part is
the information entered in any of the intermediate pages and information deduced from the server side
after submitting a page will be needed anywhere in the subsequent pages and moreover all of the
information will be needed in the last page.

The following, Hidden.inc, include file declares the server side variables for all the state involved, a
helper function that will be used every time at the beginning of a page on the server side:


Var FirstName="";
Var LastName="";
Var Address="";

// The following SaveState() function will retrieve
// the submitted state from the hidden frame on any given page

Function SaveState()
{
FirstName = "";
FirstName = Request.Form("FirstName").Item;

LastName = "";
LastName = Request.Form("LastName").Item;

Address = "";
Address = Request.Form("Address").Item;

}


This include file will be included in every page on the server side.

The following is a typical client side include file, Formstate.inc, containing the hidden form, which will
have all the fields involved in the application:









Now lets move on to the actual ASP pages where the interesting action happens. This is how Name.Asp might
look:


<%@ Language=JavaScript %>

Name


<%
SaveState();
//Bunch of other server side stuff.
%>






The key is, as you might have understood is to first generate a function that will hold all the values got
from the server side (like in the above for FirstName). If a particular variable is going to get it's
value from this page then instead of initializing it from the server side variable, read it from the
client side form variable or whatever (like the above for LastName).

Then in response to submission we have to call SubmitHiddenForm() function which effectively posts all the
data to the server side and the server side again in that page generates a similar page, which will save
all the data in the client side variables of that current page. This process continues on to the last page
where probably on the server side we use all the collected information and persist to a database.

相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 360快剪辑怎么使用 36金山词霸如何屏幕取词百度收购PPS已敲定!3

最新文章 微信3.6.0测试版更新了微信支付漏洞会造成哪 360快剪辑怎么使用 360快剪辑软件使用方法介酷骑单车是什么 酷骑单车有什么用Apple pay与支付宝有什么区别 Apple pay与贝贝特卖是正品吗 贝贝特卖网可靠吗

人气排行 xp系统停止服务怎么办?xp系统升级win7系统方电脑闹钟怎么设置 win7电脑闹钟怎么设置office2013安装教程图解:手把手教你安装与qq影音闪退怎么办 QQ影音闪退解决方法VeryCD镜像网站逐个数,电驴资料库全集同步推是什么?同步推使用方法介绍QQ2012什么时候出 最新版下载EDiary——一款好用的电子日记本