如何在复选框检查事件中将文本框的一个值复制到另一个文本框 [英] how tocopy one value of textbox to another textbox on checkbox check event
本文介绍了如何在复选框检查事件中将文本框的一个值复制到另一个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个页面,在页面的右边有帐单地址(即用户控件),在页面的左边有另一个用户控件,即送货地址.我在页面中有一个复选框,通过选中此复选框,我想用账单地址填写送货地址.我可以通过JavaScript函数有效地执行此操作,但只要这两组文本框是用户控制的,我就不知道如何执行此操作.
I have a page that in the right side I have billing address (that is user control) and on the left side I have another user control that is shipping address. I have a checkbox in the page that by checking this checkbox I would like to fill out the shipping address with billing address. I usefully do this with JavaScript function but as long as here these 2 set of textboxes are user control I dont know how I can do this.
推荐答案
make chechbox => ; Properties => autopostback = true,
在检查事件中
make chechbox=>Properties=>autopostback=true,
in check event
if(chechbox.checked)
{
textbox2.Text=textbox1.Text;
}
else
textbox2.Text="";
//or
if(chechbox.checked)
{
foreach (Control c in form1.Controls)
{
if (c.GetType().Name.ToLower() == "webusercontrol_ascx")
{
UserControl uc = (UserControl)c;
TextBox txt = (TextBox)uc.FindControl("txtShiptoName");
TextBox txt2 = (TextBox)uc.FindControl("txtShiptoName2");
txt2.Text = txt.Text;
}
}
}
else
txt2.Text="";
protected void chkCopy_CheckedChanged(object sender, EventArgs e)
{
if(txtBilling.Tex!=string.Empty)
{
txtShipping.Text=txtBilling.Text;
}
else
{
lblMessage.Tex="Billing Address is Null";
}
}
这篇关于如何在复选框检查事件中将文本框的一个值复制到另一个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文