2012-10-22 27 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 ... –