XML,Dictionary的应用---有关于页面之间接收和传递参数的又一解决方案 [原创]

*此次的程序主要解决了页面之间接收和传递多个参数的问题。

思路:以XML配置化的思想编写此DEMO的。
            主要对项目中参数接收和传递做到可配置化,宜维护。。.

文字流程图:1.A页面Response.Write一个Form到B页面;
                        2.B页面接收之后,B页面中有"下一步按钮",Press Button之后,提交从A Page接收到C Page.
                   
A Page:-----Default.aspx
B.Page------WebForm1.aspx
C.Page------WebForm2.aspx
CommonClass -----ParamClass
PageBaseClass-----BaseIPage
XML-----ParamDictionary.xml

以下是代码,供参考

ParamDictionary.xml

<ParamsDictionary>
  
<Param key="orderid" value=""/>
  
<Param key="FAV_FID1" value=""/>
  
<Param key="FAV_Status1" value=""/>
  
<Param key="FAV_NeedCheck1" value=""/>
  
<Param key="FAV_FID2" value=""/>
  
<Param key="FAV_Status2" value=""/>
  
<Param key="FAV_NeedCheck2" value=""/>
  
<Param key="FAV_CheckLine" value=""/>
  
<Param key="FlightWay" value=""/>
  
<Param key="HomeCity" value=""/>
  
<Param key="DestCity1" value=""/>
  
<Param key="DDatePeriod1" value=""/>
  
<Param key="startPeriod" value=""/>
  
<Param key="DestCity2" value=""/>
  
<Param key="startPeriod2" value=""/>
  
<Param key="ADatePeriod1" value=""/>
  
<Param key="TicketAgency_List" value=""/>
  
<Param key="ChildType" value=""/>
  
<Param key="Quantity" value=""/>
  
<Param key="DSeatClass" value=""/>
  
<Param key="AirlineChoice" value=""/>
  
<Param key="EMoneyIDList" value=""/>
  
<Param key="GetNeedGuarantee" value=""/>
  
<Param key="IsSubmitTempOrder" value=""/>
  
<Param key="NoSignupLogin" value=""/>
</ParamsDictionary>

 

    public partial class _Default : System.Web.UI.Page
    
{
        
protected void Page_Load(object sender, EventArgs e)
        
{
            
//Test Data
            string responseString = 
                
"<Form id=\"frmTemp\" action=\"WebForm1.aspx\" method=\"post\">" +
                
"<input type=\"hidden\" name=\"orderid\" value=\"1111\">" +
                
"<input type=\"hidden\" name=\"FAV_FID1\" value=\"2222\">" +
                
"<input type=\"hidden\" name=\"FAV_Status1\" value=\"3333\">" +
                
"<input type=\"hidden\" name=\"FAV_NeedCheck1\" value=\"4444\">" +
                
"<input type=\"hidden\" name=\"FAV_FID2\" value=\"5555\">" +
                
"<input type=\"hidden\" name=\"FAV_Status2\" value=\"6666\">" +
                
"<input type=\"hidden\" name=\"FAV_NeedCheck2\" value=\"7777\">" +
                
"<input type=\"hidden\" name=\"FAV_CheckLine\" value=\"8888\">" +
                
"<input type=\"hidden\" name=\"FlightWay\" value=\"9999\">" +
                
"<input type=\"hidden\" name=\"HomeCity\" value=\"aaaa\">" +
                
"<input type=\"hidden\" name=\"DestCity1\" value=\"bbbbb\">" +
                
"<input type=\"hidden\" name=\"DDatePeriod1\" value=\"ccccc\">" +
                
"<input type=\"hidden\" name=\"startPeriod\" value=\"eeee\">" +
                
"<input type=\"hidden\" name=\"DestCity2\" value=\"ffff\">" +
                
"<input type=\"hidden\" name=\"startPeriod2\" value=\"ggggg\">" +
                
"<input type=\"hidden\" name=\"ADatePeriod1\" value=\"qqqq\">" +
                
"<input type=\"hidden\" name=\"TicketAgency_List\" value=\"wwwww\">" +
                
"<input type=\"hidden\" name=\"ChildType\" value=\"eeeee\">" +
                
"<input type=\"hidden\" name=\"Quantity\" value=\"iiiiii\">" +
                
"<input type=\"hidden\" name=\"DSeatClass\" value=\"jjjjj\">" +
                
"<input type=\"hidden\" name=\"AirlineChoice\" value=\"ppppp\">" +
                
"<input type=\"hidden\" name=\"EMoneyIDList\" value=\"vvvvv\">" +
                
"<input type=\"hidden\" name=\"GetNeedGuarantee\" value=\"xxxxxx\">" +
                
"<input type=\"hidden\" name=\"IsSubmitTempOrder\" value=\"sssss\">" +
                
"<input type=\"hidden\" name=\"NoSignupLogin\" value=\"llllll\">" +

                
"</form><script language=\"javascript\">document.getElementById(\"frmTemp\").submit();</script>";

            Response.Write(responseString);
        }

    }

 

 public partial class WebForm1 : BaseIPage
    
{
        
private ParamClass paramClass = new ParamClass();

        
private BaseIPage basePage = new BaseIPage();

        
protected void Page_Load(object sender, EventArgs e)
        
{
            NameValueCollection _hiddenVariables 
= new NameValueCollection();

            
//Check RequestForm
            if (paramClass.CheckFormIsNull(Request.Form) == true)
            
{
                
//从RequestForm中取值,并存放到Dictionary
                Dictionary<String, String> paramsDictionary = paramClass.SaveParamsToDictionary(Request.Form, basePage.XMLPath);

                
//输出hidden到Page
                paramClass.WriteHiddenField(paramClass.ParseTempString(paramsDictionary, _hiddenVariables), Page.ClientScript);
            }

        }


        
protected void Button1_Click(object sender, EventArgs e)
        
{
            
//Check RequestForm
            if (paramClass.CheckFormIsNull(Request.Form) == true)
            
{
                
//从RequestForm中取值,并存放到Dictionary
                Dictionary<String, String> paramsDictionary = paramClass.SaveParamsToDictionary(Request.Form, basePage.XMLPath);

                
//跳转下一页,并传递参数
                
//string url = "http://" + ViewState["ServerName"].ToString() + "/Domestic/ConfirmOrder.aspx";
                Response.Write(paramClass.ParseTempString(paramsDictionary, "WebForm2.aspx"));
            }

        }

    }

 

 public partial class WebForm2 : BaseIPage
    
{
        
private ParamClass paramClass = new ParamClass();

        
private BaseIPage basePage = new BaseIPage();

        
protected void Page_Load(object sender, EventArgs e)
        
{
            NameValueCollection _hiddenVariables 
= new NameValueCollection();

            
//Check RequestForm
            if (paramClass.CheckFormIsNull(Request.Form) == true)
            
{
                
//从RequestForm中取值,并存放到Dictionary
                Dictionary<String, String> paramsDictionary = paramClass.SaveParamsToDictionary(Request.Form, basePage.XMLPath);

                
//输出hidden到Page
                paramClass.WriteHiddenField(paramClass.ParseTempString(paramsDictionary, _hiddenVariables), Page.ClientScript);
            }

        }

    }

 public class ParamClass
    
{
        
CheckFormIsNull

        
SaveParamsToDictionary

        
ParamDictionary

        
ParseTempString

        
WriteHiddenField
    }

  public class BaseIPage : System.Web.UI.Page
    
{
        
/// <summary>
        
/// XmlPath
        
/// </summary>

        public String XMLPath
        
{
            
get
            
{
                
return Server.MapPath("~/ParamDictionary.xml");
            }

        }

    }
posted @ 2007-02-09 13:03  RicoRui  阅读(958)  评论(0编辑  收藏  举报