打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ASP.NET添加动态主题,不能动态运行

Default1.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" 

    Inherits="Default1"%>

<!DOCTYPE html>

<html xmlns="http://www.198bona.com">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

        <div>

            <a href="https://www.csdn.net/">ASP.NET</a><br />

            <br />

            <a href="https://hao.360.com/">360浏览器</a>

            <br />

            <br />

            <input id="Button1" type="button" value="button"/>

            <br />

            <br />

            <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

                <asp:ListItem Value="Theme1">Theme1</asp:ListItem>

                <asp:ListItem Value="Theme2">Theme2</asp:ListItem>

            </asp:DropDownList>

            <br />

            <br />

            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

            <br />

            <br />

            <asp:TextBox ID="TextBox2" runat="server" SkinID="textboxSkin"></asp:TextBox>

        </div>

    </form>

</body>

</html>

Default1.aspx.cs:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class Default1 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

    {

        string url = Request.Path + "?theme=" + DropDownList1.SelectedItem.Value;

        Response.Redirect(url);

    }

    void Page_PreInit(Object sender, EventArgs e)

    {

        string theme = "Theme1";

        if (Request.QueryString["theme"] == null)

        {

            theme = "Theme1";

        }

        else 

        {

            theme = Request.QueryString["theme"];

        }

        Page.Theme = theme;

        ListItem item = DropDownList1.Items.FindByValue(theme);

        if (item != null)

        {

            item.Selected = true;

        }

    }

}

  if (Request.QueryString["theme"] == null)

        {

            theme = "Theme1";  

           //问题:设置theme="Theme1";显示的就是主题Theme1,如果先设置了theme="Theme2",就显示主题Theme2,不能和进行动态显示。

        }

        else 

        {

            theme = Request.QueryString["theme"];

        }

以上深圳市博纳网络信息技术有限公司整理(www.sabong.net)

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
asp.net局部刷新技术
[jQuery]使用jQuery.Validate进行客户端验证(高级篇
asp.net ajax 技巧--datagrid嵌套gridview
彼岸花开
dropdownlist控件取值用法介绍
[asp.net实例]全国省市数据库的应用
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服