Reputation: 3
I am doing some changes to our website and have just added a checkbox list which works great but I need the title of the page to change when I select more than one checkbox. Currently if nothing is selected it says “Summary for ….” Then when you select a check box it says “Summary for ….(name of checkbox)” When more than one checkbox is selected I need it to say “Summary for ….(multi)” I have found this code in the aspx.cs:
public partial class _default : PortalReportPage
{
public int RegionId { get; set; }
public List<int> SelectedRegions { get; set; }
public GroupStatisticCollection Stats { get; set; }
public CompanyRegionCollection Regions { get; set; }
public int PropertyCount { get; set; }
protected override void BindPath()
{
PagePath = PortalPath.GetBasicPath();
PagePath.AddNode(Container.Name, "~/company/default.aspx?id=" + Container.NodeId);
PagePath.AddNode("Reports", "~/company/reports.aspx?id=" + Container.NodeId);
}
protected void Page_Load(object sender, EventArgs e)
{
// Get all Selected regions into the SelectedRegions variable...
SelectedRegions = GetArrayFromQueryString<Int32>("region").ToList();
// TODO: remove this when the sole RegionId is ready to be replaced by the SelectedRegions list
if (SelectedRegions.Count > 0)
{
RegionId = SelectedRegions.First();
}
else
{
RegionId = 0;
}
GetStatistics();
if (!Page.IsPostBack)
{
this.Regions = CompanyRegionCollection.GetRegions(Container.NodeId);
if (this.Regions != null && this.Regions.Count > 0)
{
if (this.RegionId == 0)
{
this.PropertyCount = Regions.Sum(r => r.PropertyCount);
}
else
{
if (this.Regions.Any(r => r.NodeId == RegionId))
{
this.PropertyCount = Regions.First(r => r.NodeId == RegionId).PropertyCount;
}
}
}
if (this.PropertyCount == 0)
{
if (this.Regions.Count == 0)
{
this.PropertyCount = PropertyList.GetProperties(PropertyCriteria.NewCriteria(Container.NodeId, PropertyCriteriaSubject.Company)).TotalRecords;
}
}
BindOptionsPanel();
}
this.Title = "Summary for " + Container.Name;
if (RegionId != 0)
{
try
{
this.Title += string.Format(" ({0})", NodeBasic.GetNodeBasic(RegionId).Name);
}
catch
{
}
}
}
private void GetStatistics()
{
Stats = GroupStatisticCollection.GetCategoryStatistics(Container.NodeId, SelectedRegions);
}
private void BindOptionsPanel()
{
RegionsChecklist.Items.Add(new ListItem(" All", "0"));
foreach (var region in Regions.OrderBy(r => r.Name))
{
var item = new ListItem(region.Name, region.NodeId.ToString());
if (SelectedRegions.Contains(region.NodeId))
{
item.Selected = true;
}
RegionsChecklist.Items.Add(item);
}
}
protected void ExportButton_Click(object sender, EventArgs e)
{
ExportToCsv(this.Stats, this.Title);
}
protected void RefreshButton_Click(object sender, EventArgs e)
{
var url = "~/reports/compliance/default.aspx?id=" + Container.NodeId;
string selectedRegionString = "";
foreach (ListItem item in RegionsChecklist.Items)
{
if (item.Selected)
{
selectedRegionString = selectedRegionString + item.Value + ",";
}
}
url += "®ion=" + selectedRegionString.TrimEnd(',');
Response.Redirect(ResolveUrl(url));
}
But I am not sure what I need to change and if I am looking in the right place? Can anyone offer any advice on it please?
Upvotes: 0
Views: 96
Reputation: 3
I used what was provided to me in the answer above and managed to put together the below code snippet that works a treat.
this.Title = "Summary for " + Container.Name;
if (SelectedRegions.Count > 1)
{
RegionId = SelectedRegions.First();
this.Title = "Summary for " + Container.Name + " (Multiple Regions)";
}
else if (SelectedRegions.Count > 0)
{
RegionId = SelectedRegions.First();
this.Title += string.Format(" ({0})", NodeBasic.GetNodeBasic(RegionId).Name);
}
else
{
RegionId = 0;
this.Title = "Summary for " + Container.Name;
}
Upvotes: 0
Reputation: 1079
Handling this at client side would be a good idea.
Try following
<script type="text/javascript">
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).prop("checked") == true){
$(document).attr("title", $(this).next().text());
}
else if($(this).prop("checked") == false){
}
});
});
This will change the title of your page to the selected checkbox's "Text" property.
Make sure, you have not set AutoPostBack="True".
UPDATE - For Server Side
For handling it on server side, set the AutoPostBack = "true"
Then in code behind try following
string sTitle = "";
if (CheckBox1.Checked)
{
sTitle += CheckBox1.Text + " ";
}
if (CheckBox2.Checked)
{
sTitle += CheckBox2.Text + " ";
}
this.Title = sTitle;
Upvotes: 1