您可以使用IF声明有关。体对于电子邮件功能的onclick按钮 [英] Can You Use An If Statement For .Body For Email Functionality Onclick Of A Button

查看:87
本文介绍了您可以使用IF声明有关。体对于电子邮件功能的onclick按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页上的按钮时,在电子邮件发送详细资料给我。这是工作正常,但我在我的过程中有一个问题,其中一个问题是RAIDO按钮选择。选定的选项工作正常确认页上,但作为一个单选按钮,我需要一个如果语句我的电子邮件作为ID的将是空白的。

有谁知道我可以做到这一点。

下面是code为我的。体电子邮件的

  msg.Body = Label1.Text ++会话[pg1input]。的ToString()
           + Environment.NewLine.ToString()+
           Label2.Text ++会话[pg1dd]。的ToString()
           + Environment.NewLine.ToString()+
           Label3.Text ++会话[PG2]。的ToString()
           + Environment.NewLine.ToString()+
           Label4.Text ++会话[pg2Yes]。的ToString()
           + Environment.NewLine.ToString()+
           Label4.Text ++会话[pg2No]的ToString()。

从上面的code,下面是单选按钮行所以无论是'pg2Yes将显示为空白或pg2No将根据选择的单选按钮是空白的。

  Label4.Text ++会话[pg2Yes]。的ToString()
+ Environment.NewLine.ToString()+
Label4.Text ++会话[pg2No]的ToString()。

标识preFER如果我只是显示在一个label4和选定的单选按钮。

我曾尝试

  Label4.Text ++会话[pg2Yes]的ToString()+会话。[pg2No]的ToString()。

但这casued的电子邮件不被发送。

下面的HTML是我所确认页面上用于显示所选择的培训相关的单选按钮

 < D​​IV CLASS =表单组>
     < D​​IV CLASS =COL-XS-12>
          < ASP:标签ID =Label4级=COL-MD-3控制标签=服务器文本=孩子?>< / ASP:标签>
          < D​​IV CLASS =COL-MD-3的形式控制静电>
               <如果%(会话[pg2Yes] ==是)
               {%GT;
                    <%=会话[pg2Yes]%GT;
               <%}              如果(会话[pg2No] ==否)
              {%GT;
                    <%=会话[pg2No]%GT;
              <%}%GT;
          < / DIV>
      < / DIV>
 < / DIV>


解决方案

无法经过近一个月的努力排序了这一点相信的,它只是来找我,只要使用相同的会议名称为单选按钮,并猜测它的工作。

更新的.cs code

 如果(PhoneRadioButton.Checked)
    {
        会话[prefContactRadioButton] = PhoneRadioButton.Checked? 电话 : ;
    }
    否则,如果(EmailRadioButton.Checked)
    {
        会话[prefContactRadioButton] = EmailRadioButton.Checked? 电子邮件:;
    }

然后更新了我的确认页叫我新的会议变量

 < D​​IV CLASS =表单组>
        < ASP:标签ID =Step01ContactMethod级=COL-XS-6 COL-SM-3控制标签=服务器文本=preferred接触的方法:>< / ASP :标签>
        < D​​IV CLASS =COL-XS-6 COL-SM-9表格控制静电>
            <%=会话[prefContactRadioButton]%GT;
        < / DIV>
    < / DIV>

和finaly更新了我的确认页电子邮件正文

  msg.Body = Step01ContactMethod.Text ++会话[prefContactRadioButton]的ToString()。

和瞧它的工作原理。

I have a button on a page when sends the details to me in an email. This is working fine but i have an issue as one of the questions during my process is a raido button selection. The selected option is working fine on my confirmation page but as its a radio button i'll need an if statement for my email as one of the id's will be blank.

Does anyone know how i can do this.

Below is the code for my .body of the email

msg.Body = Label1.Text + " " + Session["pg1input"].ToString()
           + Environment.NewLine.ToString() +
           Label2.Text + " " + Session["pg1dd"].ToString()
           + Environment.NewLine.ToString() +
           Label3.Text + " " + Session["pg2"].ToString()
           + Environment.NewLine.ToString() +
           Label4.Text + " " + Session["pg2Yes"].ToString()
           + Environment.NewLine.ToString() +
           Label4.Text + " " + Session["pg2No"].ToString();

From the code above, the following is the radio button row so either 'pg2Yes' will be blank or 'pg2No' will be blank depending on the radio button selected

Label4.Text + " " + Session["pg2Yes"].ToString()
+ Environment.NewLine.ToString() +
Label4.Text + " " + Session["pg2No"].ToString();

Id prefer if i just have one label4 displayed and the radio button selected.

I did try

Label4.Text + " " + Session["pg2Yes"].ToString() + Session["pg2No"].ToString();

But this casued the email not to be sent.

The HTML below is what i have used on the confirmation page to display the relevent radio button selected

<div class="form-group">
     <div class="col-xs-12">
          <asp:Label ID="Label4" class="col-md-3 control-label" runat="server" Text="Kids?"></asp:Label>
          <div class="col-md-3 form-control-static">                            
               <% if (Session["pg2Yes"] == "Yes")
               {%>
                    <%=Session["pg2Yes"] %>
               <%}

              if (Session["pg2No"] == "No")
              {%>
                    <%=Session["pg2No"] %>
              <%} %>
          </div>
      </div>
 </div>

解决方案

Can't belive after nearly a month of trying sort this out, its just come to me, Just use the same session name for both radio buttons, and guess what it worked.

Updated .cs code

    if (PhoneRadioButton.Checked)
    {
        Session["PrefContactRadioButton"] = PhoneRadioButton.Checked ? "Phone" : "";
    }
    else if (EmailRadioButton.Checked)
    {
        Session["PrefContactRadioButton"] = EmailRadioButton.Checked ? "Email" : "";
    }

Then updated my confirmation page to call my new session variable

    <div class="form-group">
        <asp:Label ID="Step01ContactMethod" class="col-xs-6 col-sm-3 control-label" runat="server" Text="Preferred method of contact:"></asp:Label>
        <div class="col-xs-6 col-sm-9 form-control-static">                            
            <%=Session["PrefContactRadioButton"] %>
        </div>
    </div>

And finaly updated my confirmation page email body

msg.Body = Step01ContactMethod.Text + " " + Session["PrefContactRadioButton"].ToString();

And voila it works.

这篇关于您可以使用IF声明有关。体对于电子邮件功能的onclick按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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