2012-10-22 28 views
0

中查找控件名称的表单值我需要用值替换电子邮件中的占位符。占位符和表单控件名称是一个自定义列表<MailReplacements>,这有,例如:从参数

replacement.placeholder = "[UserName]", 
replacement.formcontrol = "NameText.Text", 

由于[UserName]简直是我想用什么,它在我的string.Replace的伟大工程。但是,如何在我的string.replace中使用NameText.Text的VALUE值?如果我使用:

message.replace(replacement.placeholder, replacement.formcontrol); 

我理解得到其中[UserName]替换NameText.Text的消息。我怎样才能取代NameText.Text(即“Joe Blow”)的价值?

[UserName]NameText.Text关联来自web.config中的自定义配置。所以,我并不是故意使用NameText.Text作为字符串,而是将它作为字符串接收。

我不知道如何将该字符串转换为它所表示的值。

+0

replacement.formcontrol = NameText.Text做你尝试删除周围NameText.Text – Karthik

+0

报价是否使用[web表单(http://msdn.microsoft.com/ en-us/library/31hxzsdw%28v = vs.100%29.aspx)或[winforms](http://msdn.microsoft.com/zh-cn/library/system.windows.forms.control.controlcollection.find %28V = VS.100%29.aspx)? –

回答

0

我刚刚发现的FindControl:

var StoredPlaceholders = (CustomConfigurationSection)ConfigurationManager.GetSection("MailPlaceholders"); 
foreach (CustomConfigurationSection placeholder in StoredPlaceholders.SubSections["placeholder"]) 
      { 
       MailReplacements.Add(new MailPlaceholder 
       { 
        Placeholder = placeholder.Attributes["name"], 
        Formcontrol = placeholder.Attributes["form"] 
       }); 
      } 
      foreach (MailPlaceholder replacement in MailReplacements) 
      { 
       if (!String.IsNullOrEmpty(replacement.Formcontrol)) 
       { 
        TextBox txt = RequestForm.FindControl(replacement.Formcontrol) as TextBox; 
        if (txt != null) replacement.ReplacementValue = txt.Text; 
       } 
      } 
+0

对不起,我应该在我的评论中更加明确...我收录的链接指向你FindControl ... –