0

電子メール メッセージのプレースホルダーを値に置き換える必要があります。プレースホルダーとフォーム コントロール名はカスタム リスト<MailReplacements>にあります。たとえば、次のようになります。

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

[UserName]文字通り私が使いたいものなので、私のstring.Replace. NameText.Textただし、 string.replace でVALUE を使用するにはどうすればよいですか? 私が使用する場合:

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

[UserName]当然のことながら、 whereが に置き換えられたというメッセージが表示されますNameText.TextNameText.Text(つまり、"Joe Blow")の値に置き換えるにはどうすればよいですか?

[UserName]とのNameText.Text関連付けは、 のカスタム構成からのものweb.configです。なので、わざとNameText.Text文字列として使っているのではなく、文字列として受け取っています。

その文字列をそれが表す値に変換する方法がわかりません。

4

1 に答える 1

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;
                }
            }
于 2012-10-22T20:36:59.413 に答える