Custom form-form URL parameter Processing

Source: Internet
Author: User

Today, we will describe how to transfer URL parameters during the process of jumping in a custom form.

During normal development, when passing parameters through a URL, we will certainly define a meaningful parameter name for receiving the page to get the request. This is no problem, however, in a user-defined form, the parameter names are usually fixed, and the names recognized by the system are nothing more than the same, so we can no longer pass parameters through more & symbols. What should we do? We can specify a certain format to list parameters and pass them through a fixed parameter name. The format is as follows: ppi_id | ppi20100304001, psf_id | psf20101210002.

Such parameter names are concise and easy to write, and can be well recognized by the system. It is obvious that parameters are separated, "|" is used to separate the parameter name from the parameter value. As for the name in the URL, it is called Param.

In terms of processing the receiving page, it is processed through an independent parameter class here, because the form parameters in the system are transmitted in this way, so there must be a lot of use, it is convenient to make parameter functions independent. You can use a unified method to parse form parameters to better maintain them. Paste it directlyCodeRight:

 1   ///   <Summary>  2       ///  Parameter separation auxiliary classes, such as: ppi_id | ppi20100304001, psf_id | psf20101210002, 3       ///  Returns the list of key-value information for splitting parameters.  4       ///   </Summary>  5   [Serializable]  6       Public   Class  Splitparam  7   {  8           ///   <Summary> 9           ///  Parameter string  10           ///   </Summary>  11           ///   <Param name = "Param"> </param>  12           Public Splitparam ( String  Param)  13   {  14              This . Param = Param;  15   }  16   17           Public   Override   String  Tostring ()  18   {  19               Return  Param;  20   } 21   22           Private   String _ Param = String  . Empty;  23           ///   <Summary>  24           ///  Parameter string  25           ///   </Summary>  26           Public  String  Param  27   {  28               Get { Return  _ Param ;}  29               Private   Set  30   {  31                   If (! String . Isnullorempty (value ))  32   {  33 _ Param = Value;  34   }  35   }  36   }  37   38           ///   <Summary>  39          ///  Save the resolved parameter list  40           ///   </Summary>  41           Private Dictionary < String , String > _ Paramlist = Null  ;  42   43           ///   <Summary>  44          ///  Obtains the list of parsed parameters, which can be used for parameter replacement.  45           ///   </Summary>  46           ///   <Returns> </returns>  47           Public Dictionary < String , String > Getparamlist ()  48   { 49               If (_ Paramlist = Null  )  50   {  51 _ Paramlist = New Dictionary < String , String > ();  52                   String [] Lista = _ Param. Split ( '  , '  );  53                   If (Lista = Null | Lista. Length = 0  )  54   {  55                       Return  _ Paramlist;  56   }  57   58                  String  [] Listb;  59                   Foreach ( String Item In  Lista)  60   {  61                       If (! String  . Isnullorempty (item ))  62   {  63 Listb = item. Split ( '  |  '  );  64                           If (Listb! = Null & Amp; listb. Length & gt; 1  )  65   {  66 _ Paramlist. Add (listb [ 0 ], Listb [ 1 ]);  67   }  68   }  69   }  70   }  71               Return  _ Paramlist;  72   }  73   74           ///  <Summary>  75           ///  Get value based on key value  76           ///   </Summary>  77           ///   <Param name = "key"> </param>  78           ///   <Returns> </returns>  79           Public   String Getvaluebykey (String  Key)  80   {  81   Getparamlist ();  82               If (_ Paramlist! = Null && _ Paramlist. containskey (key ))  83   {  84                   Return  _ Paramlist [Key]; 85   }  86               Return   ""  ;  87   }  88 }

This class uniformly manages parameters and provides methods to obtain parameter values based on parameter names.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.