博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

用代码的方式生成Form并提交表单

Posted on 2009-08-17 17:09  日月星尘  阅读(381)  评论(0)    收藏  举报
 /// <summary>
        
/// 创建Form HTML代码
        
/// </summary>
        
/// <param name="parma">需要添加的参数</param>
        
/// <param name="url">网关的Url</param>
        protected string GetForm(Dictionary<stringstring> parma, string url)
        {
            
string formItem = "<input type='hidden' name='{0}' value='{1}'>";
            StringBuilder html 
= new StringBuilder();

            html.AppendLine(
"<form name='Gateway' method='post'" + " action =" + url + ">");

            
foreach (KeyValuePair<stringstring> item in parma)
            {
                html.AppendLine(
string.Format(formItem, item.Key, item.Value));
            }

            html.AppendLine(
"<input type='submit'id='submit' value='提交' style='display:none'/>");
            html.AppendLine(
"</form>");
            
//html.AppendLine("<script type='text/javascript'>window.document.Gateway.submit();</script>");
            html.AppendLine("<script type='text/javascript'>window.document.getElementById('submit').click();</script>");
            
return html.ToString();
        }