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

推荐订阅源

Project Zero
Project Zero
F
Fortinet All Blogs
Recent Announcements
Recent Announcements
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
WordPress大学
WordPress大学
Engineering at Meta
Engineering at Meta
S
Schneier on Security
N
News and Events Feed by Topic
N
News | PayPal Newsroom
H
Help Net Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
The Exploit Database - CXSecurity.com
Attack and Defense Labs
Attack and Defense Labs
博客园 - Franky
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
A
About on SuperTechFans
AWS News Blog
AWS News Blog
S
Secure Thoughts
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
C
Cybersecurity and Infrastructure Security Agency CISA
V2EX - 技术
V2EX - 技术
Recorded Future
Recorded Future
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
MyScale Blog
MyScale Blog
Martin Fowler
Martin Fowler
Help Net Security
Help Net Security
人人都是产品经理
人人都是产品经理
Latest news
Latest news
C
Cyber Attacks, Cyber Crime and Cyber Security
大猫的无限游戏
大猫的无限游戏
The Last Watchdog
The Last Watchdog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
H
Hacker News: Front Page
P
Proofpoint News Feed
N
News and Events Feed by Topic
H
Heimdal Security Blog
L
Lohrmann on Cybersecurity
有赞技术团队
有赞技术团队
L
LangChain Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog

博客园 - 陋室

成功与一截树枝 sql 操作全集-整理收藏 JavaScript使用技巧精萃(转载) 提示按下大写键的控件:MQTool(提供下载) 如何在mail的正文显示图片 NET设计模式之一:装饰模式(Decorator Pattern) 微软AJAX 教学系列第一讲:ScriptManager控件 微软AJAX 教学系列第一讲:局部刷新Partial Page Updates(翻译) 李开复:21世纪最需要的7种人才 Building a File Service 超卓越的你_读完后让你恢复自信 how to write professional business letters? 到底什么是托管,什么是非托管的研究 数据库设计中的五个范式(本文转载,收藏下) 如何直接用XML做数据源? ASP.NET程序的优化建议<转> ASP.NET部署与安装_MSI制作图文教程. 在打包的时候,创建应用程序池,并自动将程序assign到新创建的池中(MSI制作) Understand SQL Cache Notifications
ASP.NET 中在指定的位置处插入字符
陋室 · 2008-06-05 · via 博客园 - 陋室

这是论坛中的一个问题,很多人经常会遇到,就贴出来。

完整代码如下,实现在光标处插入上传后的文件名:

 1<%@ Page Language="C#" AutoEventWireup="true" %>
 2<script runat="server">
 3  protected void Page_Load(object sender, EventArgs e)
 4  {
 5  TextBox1.Attributes.Add("onclick""getCursor('" + TextBox1.ClientID + "','" + Hidden1.ClientID + "');");
 6  }

 7  protected void Button1_Click(object sender, EventArgs e)
 8  {
 9  string fileName = FileUpload1.FileName;
10  //保存文件省略
11  int pos = 0;
12  Int32.TryParse(Hidden1.Value, out pos);
13  TextBox1.Text = TextBox1.Text.Insert(pos, fileName);
14  }

15
</script>
16<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
17<html xmlns="http://www.w3.org/1999/xhtml">
18<head runat="server">
19<title>ASP.NET 中在指定的位置处插入字符 </title>
20<script type="text/javascript">
21    function getCursor(param1,param2)
22    {
23    var pos = 0;   
24    var t = document.getElementById(param1);
25    if(document.selection )
26    {
27      t.focus();
28      var rng = document.selection.createRange();
29      rng.setEndPoint("EndToStart", t.createTextRange());
30      pos = rng.text.length;
31    }

32    else if(t.selectionStart)
33    {
34      pos = t.selectionStart;
35    }

36    document.getElementById(param2).value = pos;
37    }

38
</script>
39
40</head>
41<body>
42<form id="form1" runat="server">
43<div>
44  <asp:TextBox ID="TextBox1" runat="server" Width="629px">123456789 </asp:TextBox>
45  <input id="Hidden1" type="hidden" runat="server" />
46</div>
47<asp:FileUpload ID="FileUpload1" runat="server" />
48<asp:Button ID="Button1" runat="server" Text="上载文件" OnClick="Button1_Click" />
49</form>
50</body>
51</html>

转自:http://blog.csdn.net/net_lover/archive/2008/05/25/2480585.aspx