well, by default my radiobuttonList have a option checked of the 4 options, and so the radiobuttonLIst_IndexChanged is called and load the right controls, here is the code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using System.Data.SqlClient;
public partial class editors_NewsLetterControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String result;
try
{
SmtpMail.SmtpServer = "smtp.gmail.com";
MailMessage mail = new MailMessage();
mail.To = "mail@somemail";
mail.From = "Custom subject";
if (RadioButtonList1.SelectedValue == "Type 1 Enquiry")
{
mail.Body = "Type 1 Enquiry \n\nEmail: " + emailTextBox.Text + "\n\n" + NewsLetterTextBox.Text;
} if (RadioButtonList1.SelectedValue == "Type 2 Enquiry")
{
mail.Body = "Type 2 Enquiry\n\nName: " + nameTextBox.Text.ToString() + "\nEmail: " + emailTextBox.Text + "\n\n" + NewsLetterTextBox.Text;
}
if (RadioButtonList1.SelectedValue == "Type 3 Enquiry")
{
mail.Body = "Type 3 Enquiry \n\nName: " + nameTextBox.Text.ToString() + "\nCompany: " + companyTextBox.Text.ToString() + "\nPhone: " + phoneTextBox.Text.ToString() + "\nEmail: " + emailTextBox.Text + "\nWebsite: " + webTextBox.Text.ToString() + "\n\nMessage:\n\n" + NewsLetterTextBox.Text;
} if (RadioButtonList1.SelectedValue == "Type 4 Enquiry")
{
mail.Body = "Type 4 Enquiry \n\nContact Name: " + contacNameTextBox.Text.ToString() + "\nCompany Name: " + companyNameTextBox.Text.ToString() + "\nCompany Description: " + companyDescriptionTextBox.Text.ToString() + "\nWebsite: " + websiteLinksTextBox.Text + "\nPage that links back yo us: " + pageLinkingBackTextBox.Text.ToString() + "\nEmail: " + emailLinksTextBox.Text.ToString()+"\n\nMessage:\n\ n"+commentsTextBox.Text.ToString();
}
mail.Subject = subjectTextBox.Text.ToString();
/* Some others implementations */
}
// This is the posible method problem....
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue == "Type 1 Enquiry")
{
nameTextBox.Visible = false;
nameLabel.Visible = false;
companyTextBox.Visible = false;
companyLabel.Visible = false;
phoneTextBox.Visible = false;
phoneLabel.Visible = false;
emailTextBox.Visible = true;
emailLabel.Visible = true;
webTextBox.Visible = false;
websiteLabel.Visible = false;
MultiView1.ActiveViewIndex = 0;
subjectTextBox.Text = "Type 1 Enquiry";
} if (RadioButtonList1.SelectedValue == "Type 2 Enquiry")
{
nameTextBox.Visible = true;
nameLabel.Visible = true;
companyTextBox.Visible = true;
companyLabel.Visible = true;
phoneTextBox.Visible = true;
phoneLabel.Visible = true;
emailTextBox.Visible = true;
emailLabel.Visible = true;
webTextBox.Visible = true;
websiteLabel.Visible = true;
MultiView1.ActiveViewIndex = 0;
subjectTextBox.Text = "Type 2 Enquiry";
} if (RadioButtonList1.SelectedValue == "Type 3 Enquiry")
{
nameTextBox.Visible = true;
nameLabel.Visible = true;
companyTextBox.Visible = false;
companyLabel.Visible = false;
phoneTextBox.Visible =false;
phoneLabel.Visible = false;
emailTextBox.Visible = true;
emailLabel.Visible = true;
webTextBox.Visible = false;
websiteLabel.Visible = false;
MultiView1.ActiveViewIndex = 0;
subjectTextBox.Text = "Type 3 Enquiry";
} if (RadioButtonList1.SelectedValue == "Type 4 Enquiry")
{
MultiView1.ActiveViewIndex = 1;
}
}
protected void RadioButtonList1_Init(object sender, EventArgs e)
{
}
}
AND THIS IS THE ASPX
<%@ Page Language="C#" MasterPageFile="~/asd.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="somecontrol" Title="Some tittle" ValidateRequest="false" EnableSessionState="True" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br />
<center>
<table id="table_big" align="center" cellpadding="0" cellspacing="0" language="javascript"
onclick="return table_big_onclick()" style="border-right: black 1px solid; border-top: black 1px solid;
border-left: black 1px solid; border-bottom: black 1px solid">
<tr>
<td class="table_big_title" colspan="2" style="height: 14px" align=center>
<span style="font-size: 18px">Contact Us</span></td>
</tr>
<tr>
<td class="table_big_row">
<div align="justify" style="text-align: justify">
<br />
<br />
<table>
<tr>
<td style="width: 159px">
<asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="Small" Text="Select contact mode:"></asp:Label></td>
<td style="width: 248px">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedI ndexChanged" CausesValidation="True" OnLoad="RadioButtonList1_SelectedIndexChanged" OnInit="RadioButtonList1_Init">
<asp:ListItem Selected="True">Type 1 Enquiry</asp:ListItem>
<asp:ListItem>Type 2 Enquiry</asp:ListItem>
<asp:ListItem>Type 3 Enquiry</asp:ListItem>
<asp:ListItem>Type 4 Enquiry</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</table>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0" >
<asp:View ID="View1" runat="server">
<table style="position: static">
<tr>
<td style="width: 100px">
</td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="nameLabel" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Name:"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="nameTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="companyLabel" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Company:"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="companyTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="phoneLabel" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Phone:"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="phoneTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="emailLabel" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Email:"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="emailTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="websiteLabel" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Website:"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="webTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="Label5" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Subject:"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="subjectTextBox" runat="server" Style="position: static" Width="250px">General Enquiry</asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px; height: 10px;">
<asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Message:" Width="78px"></asp:Label></td>
<td style="width: 100px; height: 10px;">
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="NewsLetterTextBox" runat="server" Height="155px" Style="position: static"
TextMode="MultiLine" ToolTip="Put newsletter here, you can include html tags."
Width="541px"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" align=center><asp:Button ID="Button3" runat="server" Text="Send" OnClick="Button1_Click" style="position: static" /></td>
</tr>
</table>
</asp:View>
<asp:View ID="View2" runat="server">
<center><p>
Some text
</p>
</center>
<br />
<table style="position: static">
<tr>
<td style="width: 146px; height: 16px">
</td>
<td style="width: 100px; height: 16px">
</td>
</tr>
<tr>
<td style="width: 146px">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Contact Name:" Width="113px"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="contacNameTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 146px">
<asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Company Name:" Width="124px"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="companyNameTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 146px">
<asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Company Description:" Width="163px"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="companyDescriptionTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 146px">
<asp:Label ID="Label8" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Website:"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="websiteLinksTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 146px">
<asp:Label ID="Label7" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Page that links back to us:" Width="194px"></asp:Label>
</td>
<td style="width: 100px">
<asp:TextBox ID="pageLinkingBackTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 146px">
<asp:Label ID="Label9" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Email:"></asp:Label></td>
<td style="width: 100px">
<asp:TextBox ID="emailLinksTextBox" runat="server" Style="position: static" Width="250px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 146px">
<asp:Label ID="Label10" runat="server" Font-Bold="True" Font-Size="Small" ForeColor="Black"
Style="position: static" Text="Comments:" Width="78px"></asp:Label></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td colspan="2">
<asp:TextBox ID="commentsTextBox" runat="server" Height="155px" Style="position: static"
TextMode="MultiLine" ToolTip="Put newsletter here, you can include html tags."
Width="541px"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" align=center style="height: 15px"><asp:Button ID="Button2" runat="server" Text="Send" OnClick="Button1_Click" style="position: static" /></td>
</tr>
</table>
</asp:View>
</asp:MultiView>
<center>
</center><br />
<br />
</div>
</td>
</tr>
</table>
</center>
<center>
</center>
</asp:Content>
Also tried now with a application variable setting on every change so i set the selected value on load, it just works worst!...
|