首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >网页标题更改

问网页标题更改
EN

Stack Overflow用户
提问于 2017-02-14 10:20:48
回答 2查看 73关注 0票数 0

我正在做一些改变,我们的网站,并刚刚添加了一个复选框列表,这是很好的工作,但我需要标题的网页改变,当我选择多个复选框。目前,如果没有选择,它会写成“…摘要”)。“然后,当您选择一个复选框时,它会写成“…摘要”“当选中多个复选框时,我需要它说”…摘要“.(多)“我在aspx.cs中找到了以下代码:

代码语言:javascript
复制
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 += "&region=" + selectedRegionString.TrimEnd(','); 
        Response.Redirect(ResolveUrl(url));
    }

但我不知道我需要改变什么,如果我找对地方?有人能给我提点建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-02-15 13:38:36

我使用了在上面的答案中提供给我的内容,并设法将下面的代码片段组合在一起,这是一个不错的方法。

this.Title =“汇总”+ Container.Name;

代码语言:javascript
复制
        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;
        }
票数 0
EN

Stack Overflow用户

发布于 2017-02-14 11:29:27

在客户端处理这个问题是个好主意。

试着跟随

代码语言:javascript
复制
<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){
        }
    });
});

​

这将将页面的标题更改为选中的复选框的"Text“属性。

确保您没有设置AutoPostBack="True“。

更新-用于服务器端

要在服务器端处理它,请设置AutoPostBack = "true“

然后在后面的代码中尝试如下

代码语言:javascript
复制
 string sTitle = "";

            if (CheckBox1.Checked)
            {
                sTitle += CheckBox1.Text + " ";
            }
            if (CheckBox2.Checked)
            {
                sTitle += CheckBox2.Text + " ";
            }

            this.Title = sTitle;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42223505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档