C#如何定义一个变量,首先将文本框里的值赋给它,然后改变变量的值就能使文本框值改变
2个回答
展开全部
string a = txtLoginname.text;
txtLoginname.text = a;
如果你还想改变文本框的值来改变变量的话,用它的chang事件
txtLoginname.text = a;
如果你还想改变文本框的值来改变变量的话,用它的chang事件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="valuechang.aspx.cs" Inherits="WebApp.valuechang" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click" />
</div>
</form>
</body>
</html>
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;
namespace WebApp
{
public partial class valuechang : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void vc_PropertyChanged(object sender, EventArgs e)
{
ValueChange vc=sender as ValueChange;
TextBox1.Text = vc.Strvalue;
}
public class ValueChange
{
private string strvalue;
public event EventHandler PropertyChanged;
public string Strvalue
{
get { return strvalue; }
set
{
strvalue = value;
this.OnPropertyChanged(new EventArgs());
}
}
public ValueChange(string strvalue)
{
this.strvalue=strvalue;
}
private void OnPropertyChanged(EventArgs eventArgs)
{
if (this.PropertyChanged != null)//判断事件是否有处理函数
{
this.PropertyChanged(this, eventArgs);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ValueChange vc = new ValueChange(TextBox1.Text);
vc.PropertyChanged += new EventHandler(vc_PropertyChanged);
vc.Strvalue = "32";
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Click" />
</div>
</form>
</body>
</html>
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;
namespace WebApp
{
public partial class valuechang : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void vc_PropertyChanged(object sender, EventArgs e)
{
ValueChange vc=sender as ValueChange;
TextBox1.Text = vc.Strvalue;
}
public class ValueChange
{
private string strvalue;
public event EventHandler PropertyChanged;
public string Strvalue
{
get { return strvalue; }
set
{
strvalue = value;
this.OnPropertyChanged(new EventArgs());
}
}
public ValueChange(string strvalue)
{
this.strvalue=strvalue;
}
private void OnPropertyChanged(EventArgs eventArgs)
{
if (this.PropertyChanged != null)//判断事件是否有处理函数
{
this.PropertyChanged(this, eventArgs);
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ValueChange vc = new ValueChange(TextBox1.Text);
vc.PropertyChanged += new EventHandler(vc_PropertyChanged);
vc.Strvalue = "32";
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询