在文本框一中选择前两个字符,然后单击提交按钮,将其放在文本框二中 [英] select first two charecters from textbox one and place it in textbox two after clicking submit button

查看:77
本文介绍了在文本框一中选择前两个字符,然后单击提交按钮,将其放在文本框二中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <   html   xmlns    http://www.w3.org/1999/xhtml"> 
<      ="  服务器" <  标题 > 无标题页面<  /title  > 
<  /head  > 
<  正文 > 
    <  表单    ="   form1"  runat   >服务器"  > 
    <   div  > 
        <   asp:TextBox     ID   ="   runat   服务器" <  > 
        <   asp:TextBox     ID   ="   runat   服务器" <  > 
        <   asp:Button     ID   ="   runat   服务器" 文本  按钮"  onclick    Button1_Click" / > 
    <  /div  > 
    <  /form  > 
<  /body  > 
<  /html  >  





cs


 使用系统;
使用 System.Collections;
使用 System.Configuration;
使用 System.Data;
使用 System.Linq;
使用 System.Web;
使用 System.Web.Security;
使用 System.Web.UI;
使用 System.Web.UI.HtmlControls;
使用使用System.Web.UI.WebControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Xml.Linq;

公共 部分  Default2:System.Web .UI.页面
{
    受保护的 无效 Page_Load(对象发​​件人,EventArgs e)
    {

    }
    受保护的 无效 Button1_Click(对象发​​件人,EventArgs e)
    {
        字符串用户;
        用户= TextBox1.Text.Substring( 0  2 );
        TextBox2.Text =用户;
    }
} 

解决方案

在使用string.substring时,不要忘记检查字符串是否为null或为空,否则将发生异常. blockquote>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>
</html>





cs


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string user;
        user = TextBox1.Text.Substring(0, 2);
        TextBox2.Text = user;
    }
}

解决方案

while using string.substring, don''t forget to check whether the string is null or empty, orelse exception will occur.


这篇关于在文本框一中选择前两个字符,然后单击提交按钮,将其放在文本框二中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆