如何在.ascx的文本框中显示值,说从.ascx的A说B [英] how to show value in a textbox of .ascx say A from .ascx say B

查看:77
本文介绍了如何在.ascx的文本框中显示值,说从.ascx的A说B的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个用户控件,其中包含一个文本框,
现在,我想在其中显示一些价值,但来自另一个.ascx.我该如何在c#中做到这一点.

i''ve a usercontrol which contains a textbox in it,
now i want to show some value in it but from another .ascx. How can i do that in c#.

推荐答案

您必须为用户控件创建事件处理程序,例如


后面的用户控制代码
公共事件EventHandler SaveReport_Click;
You have to Create Event Handler for User control like this

User control code behind

public event EventHandler SaveReport_Click;
protected void BtnSaveReport_Click(object sender, EventArgs e)
       {
           SaveReport_Click(sender, e);
           getReportName = TxtReportName.Text;          

       }



UserControl.ascx



UserControl.ascx

<asp:Button ID="BtnSaveReport" runat="server" Text="Save Report" Width="95px"
                                                   OnClick="BtnSaveReport_Click"/>



基于usercontrol按钮单击触发正常事件以调用按钮单击.
上一个是我们正确创建的事件处理程序.我们创建了get和set methord来为该变量分配值.呼叫全球事件.



base on usercontrol button click fire the normal event to call button click.
Previours we created event handler right.. And we create get and set methord to assign the value for that variable. Call the Global event.

private string getReportName;

       public string GetReportName
       {
           get { return getReportName; }
           set { getReportName = value; }
       }




aspx页面.

实施用户控件后,根据用户控件ID,我们可以在aspx页面中获取该全局事件.




aspx Page.

After implement the user controls, based up usercontrols id we can get that global event in our aspx page.

<uc1:reportdownload id="UCISaveReport"  runat="server" xmlns:uc1="#unknown" />



然后我们再创建一个事件句柄来调用该方法,就可以得到该值.



and we create one more event handle to call the methord and we get that value.

UCISaveReport.SaveReport_Click += new EventHandler(BtnSaveReport_Click);




后面的aspx.cs代码



aspx.cs code behind

protected void BtnSaveReport_Click(object sender, EventArgs e)
        {
            SaveReport();
        }


这篇关于如何在.ascx的文本框中显示值,说从.ascx的A说B的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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