惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - 馒头

加载安卓SDK失败的办法 WCF服务端配置容易被忽略的细节问题 对 wcf 的安全机制传输安全的疑惑求教 [转].net试用分布式数据库事务com+ [转].net下跨数据分布式事务的处理办法TransactionScope [转]Page的生存周期 如何在客户端清除fileUpLoad控件的文件路径 - 馒头 - 博客园 来自朋友的关爱 T_Sql之Str()和Cast .net word编程对象简介 .Net将数据导出Word Oracle 与SQL Server 2000常用函数对照 [摘抄] 项目中除了需求外还需要知道的问题 .net调用数据库存储过程应当注意的问题 [转]Asp.Net下导出/导入规则的Excel(.xls)文件 [转]常用表达式 [转]ASP.NET提供文件下载函数 [转]项目的成败 如何向存储过程传送数组
[转]如何获得动态添加的html控件的值 - 馒头 - 博客园
馒头 · 2007-09-24 · via 博客园 - 馒头

<head runat="server">
    <title>页面</title>
    <!--文件上传-->
    <script language="JavaScript">
    var i  =0;
    function addFileControl()
    {
       
        if(i<4)
        {
     var str = '<INPUT type="file" NAME="File"><br/>'
     document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str)
     i++;
     }else
     {
         alert('只允许同时5个上传!')
     }
    }
  </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   <input onclick="addFileControl()" type="button" value="增加上传"><div id ="FileCollection"> <INPUT type="file" name="File"  runat="server" id="File1" /></div>
   <div> </form>
</body>
</html>

后台代码:

 //只允许上传5张图片 在数据库里设置5个image字段即可
        string image1 = "";
        string image2 = "";
        string image3 = "";
        string image4 = "";
        string image5 = "";
        int fileCount = 0;
        System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
        for (fileCount = 0; fileCount < files.Count; fileCount++)
        {
            //定义访问客户端上传文件的对象
            System.Web.HttpPostedFile postedFile = files[fileCount];
            string fileName, fileExtension;
            //取得上传得文件名
            fileName = System.IO.Path.GetFileName(postedFile.FileName);
            if (fileName != String.Empty)
            {
                //取得文件的扩展名
                fileExtension = System.IO.Path.GetExtension(fileName);
                //上传的文件信息
                //strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
                //strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
                //strMsg.Append("上传文件的文件名:" + fileName + "<br>");
                //strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr color=red>");

                if (fileCount == 0)
                {
                    image1 = "../upload/" + fileName;

                }
                if (fileCount == 1)
                {
                    image2 = "../upload/" + fileName;

                }
                if (fileCount == 2)
                {
                    image3 = "../upload/" + fileName;

                }
                if (fileCount == 3)
                {
                    image4 = "../upload/" + fileName;

                }
                if (fileCount == 4)
                {
                    image5 = "../upload/" + fileName;

                }
                postedFile.SaveAs(Server.MapPath("http://www.cnblogs.com/uploadfiles/") + fileName);
            }
        }

=========================第二种获得多个文本框的值=======================

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>页面</title>
   <!--文本框上传-->
   <script language=javascript>
        var j=0;
        function showAddDiv()
           {
           if(j<5)
           {
            var temp="文本框"+(j+1)+":<input style='width:90px'; id='txtSelect' name='txtSelect' />";
            document.getElementById("addText").insertAdjacentHTML("BeforeEnd",temp);
            j++;
           }
           else
           {
            alert('只能增加5个答案');
           }
          
           }
    </script>
</head>
<body>
    <form id="form1" runat="server">
   <a href="javascript:;" onclick="showAddDiv();"><font size=2px>增加文本框</font></a>
   <span id="addText"><input type="text"  style="width:90px" id="txtSelect" name="txtSelect" runat=server />
       <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="保存文本框的值" /></div>
    </form>
</body>
</html>

后台代码:

 string text = Request.Form["txtSelect"].ToString().Trim();
        if (text == null || text == "")
        {
            this.RegisterStartupScript("istextnull", "<script>alert('请输入文本框的值:');</script>");
            return;
        }
        string[] arr = text.Split(',');
        if (arr[0].ToString() == null || arr[0].ToString() == "")
        {
            this.RegisterStartupScript("istextnull", "<script>alert('请输入文本框的值');</script>");
            return;
        }
        /*程序执行到这里的话,说明文本框里面已经有值了 现在需要把 arr数组拆分开即可 插入数据库即可*/