Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 值没有从ascx codebehind传递到javascript?_C#_Asp.net_User Controls_Smtp_Ascx - Fatal编程技术网

C# 值没有从ascx codebehind传递到javascript?

C# 值没有从ascx codebehind传递到javascript?,c#,asp.net,user-controls,smtp,ascx,C#,Asp.net,User Controls,Smtp,Ascx,我使用它将值从ascx codebehind传输到具有3个标签的ascx用户控件 string text1 = fr.data[0].name; string text2 = m.data[0].name; string text3 = m.data[0].name; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), " ", "document.getElementById(

我使用它将值从ascx codebehind传输到具有3个标签的ascx用户控件

 string text1 = fr.data[0].name;
        string text2 = m.data[0].name;
        string text3 = m.data[0].name;
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), " ", "document.getElementById('lblfriend').innerHTML ='" + text1 + "'; return true;", true);
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), " ", "document.getElementById('lblmyname').innerHTML ='" + text2 + "'; return true;", true);
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), " ", "document.getElementById('lblmyname1').innerHTML ='" + text3 + "'; return true;", true);
但是,值不会被传递,我希望将这些标签呈现为Html,以便它们可以嵌入电子邮件中


请帮忙

看看呈现的页面,你确定你的控件名为
lblFriend
等等,我假设它们比这更重要一些

您可能需要使用

"document.getElementById('" + lblfriend.ClientID + "').innerHTML ='

看看呈现的页面,你确定你的控件名为
lblFriend
等等,我假设它们比这更重要一些

您可能需要使用

"document.getElementById('" + lblfriend.ClientID + "').innerHTML ='

您可以在UserControl的codebehind中将标签文本作为字符串属性公开。然后,在呈现usercontrol时,将值传递给它,它将呈现标签的文本

UserControl的代码隐藏:

public partial class WebUserControl1 : System.Web.UI.UserControl
{
    private string _Friend;

    public string Friend
    {
        get
        {
            return _Friend;
        }
        set
        {
            _Friend = value;
            lblfriend.Text = value;
        }
    }

    private string _MyName;

    public string MyName
    {
        get
        {
            return _MyName;
        }
        set
        {
            _MyName = value;
            lblmyname.Text = value;
            lblmyname1.Text = value;
        }
    }

}
然后可以在父控件/页面中加载值:

        string text1 = fr.data[0].name;
        string text2 = m.data[0].name;                    
        MyUserControl.Friend = text1;
        MyUserControl.MyName = text2;

您可以在UserControl的codebehind中将标签文本作为字符串属性公开。然后,在呈现usercontrol时,将值传递给它,它将呈现标签的文本

UserControl的代码隐藏:

public partial class WebUserControl1 : System.Web.UI.UserControl
{
    private string _Friend;

    public string Friend
    {
        get
        {
            return _Friend;
        }
        set
        {
            _Friend = value;
            lblfriend.Text = value;
        }
    }

    private string _MyName;

    public string MyName
    {
        get
        {
            return _MyName;
        }
        set
        {
            _MyName = value;
            lblmyname.Text = value;
            lblmyname1.Text = value;
        }
    }

}
然后可以在父控件/页面中加载值:

        string text1 = fr.data[0].name;
        string text2 = m.data[0].name;                    
        MyUserControl.Friend = text1;
        MyUserControl.MyName = text2;

仅使用控件的ClientID写入一个RegisterClient脚本 e、 g


仅使用控件的ClientID写入一个RegisterClient脚本 e、 g


您的问题是,您是否通过fr.data[0].name获取数据,m.data[0].name?或者您对Page.ClientScript.RegisterClientScriptBlock代码有问题?一个问题是,所有RegisterClientScriptBlock调用都使用相同的密钥,因此实际上只注册了第一个密钥。您的问题是,是否通过fr.data[0]获取数据。名称,m.data[0]。名称?或者您对Page.ClientScript.RegisterClientScriptBlock代码有问题?一个问题是所有RegisterClientScriptBlock调用都使用相同的键,因此只有第一个真正注册。是的,名称相同,现在我可以看到值。但是,当我在aspx页面上访问此usercontrol时,将其转换为html,我无法访问其中的文本未显示的标签“StringBuilder htmlResponse=new StringBuilder();使用(StringWriter sw=new StringWriter(htmlResponse)){使用(HtmlTextWriter textWriter=new HtmlTextWriter(sw)){Control emailBody=Page.LoadControl(“myEmailtemplate.ascx”);emailBody.RenderControl(textWriter);emailHtml=htmlResponse.ToString();会话[“emailHtml”]=emailHtml;}`这些值没有以文本形式传递到Asp.net标签是的,名称相同,现在我可以看到这些值,但是当我在aspx页面上访问此usercontrol并将其转换为html时,我无法访问标签中的文本,它不会显示`StringBuilder htmlResponse=new StringBuilder();使用(StringWriter sw=new StringWriter(htmlResponse)){使用(HtmlTextWriter textWriter=new HtmlTextWriter(sw)){Control emailBody=Page.LoadControl(“myEmailtemplate.ascx”);emailBody.RenderControl(textWriter);emailHtml=htmlResponse.ToString();会话[“emailHtml”]=emailHtml;}`这些值没有以文本形式传递到Asp.net标签对不起,语法错误,我已修改,请立即检查语法错误,我已修改,请立即检查