PDA

View Full Version : سوال: افزودن استایل بصورت رندم؟



hamid1988
چهارشنبه 22 اردیبهشت 1389, 23:02 عصر
برای قالب وبسایتم چند فایل Css طراحی کرده ام و میخام هنگام بارگذاری صفحه یکی از Cssها بصورت رندم به سایت اعمال بشه، لطفاَ راهنماییم کنید.
ممنون!

maxpayn2
پنج شنبه 23 اردیبهشت 1389, 10:09 صبح
برای اعمال شدن استایل به صورت اتوماتیک یک فیلم ویدئویی در سایت www.asp.net هست که اگه اشتباه نکنم اینه : Customize my Site with Profiles and Themes . برای رندوم بودن هم میتونی یک آرایه از اسم استایل هات درست کنی و هر دفعه یک عضو آرایه رو به صورت رندوم انتخاب کنه و اعمال کنه

hamid1988
پنج شنبه 23 اردیبهشت 1389, 11:27 صبح
برای اعمال شدن استایل به صورت اتوماتیک یک فیلم ویدئویی در سایت www.ASP.NET (http://www.ASP.NET) هست که اگه اشتباه نکنم اینه : Customize my Site with Profiles and Themes . برای رندوم بودن هم میتونی یک آرایه از اسم استایل هات درست کنی و هر دفعه یک عضو آرایه رو به صورت رندوم انتخاب کنه و اعمال کنه
دوست عزیز من بیشتر منظورم نحوه ی افزودن رفرنس فایل css از طریق کدنویسی بود، بدون آنکه css مورد نظر رو در قسمت head رفرنس بدیم.

hamid1988
جمعه 24 اردیبهشت 1389, 09:55 صبح
کسی نیست یه راهنمایی کوچولو بکنه؟!

maxpayn2
شنبه 25 اردیبهشت 1389, 09:25 صبح
خب این کاری که گفتم هم از طریق کد انجام میشه ، اون فیلم آموزشی رو دیدی ؟

http://www.asp.net/general/videos/how-do-i-customize-my-site-with-profiles-and-themes

Freydoonk
شنبه 25 اردیبهشت 1389, 10:30 صبح
من قبلا اين كارو با يه Lable انجام دادم



<htmldir="rtl"xmlns="http://www.w3.org/1999/xhtml">



<headrunat="server">


<title> test</title>

<asp:LabelID="LblTheme"runat="server"Text=""></asp:Label>





head/>>


حالا تو كدت ميتوني اينطوري كار كني



=LblTheme.Text



"<link href=\"UI/Styles/MainStyle.css\" type=\"text/css\" rel=\"stylesheet\" />";


ميتوني ليست cssهات رو تو يه مسير نگهداري و به طور رندم بريزي تو اين ليبل

maxpayn2
شنبه 25 اردیبهشت 1389, 12:15 عصر
اینجوری اگه مستر پیج نداشته باشی مجبوری در تمام صفحات این کد رو بنویسی و اگه مسترپیج داشته باشی و الان کارت راه بیافته اگه بعدا بخوای مسترپیج به فولدر اصلی یا فرعی اضافه کنی باید به صورت دستی تو اون هم بنویسی که در این صورت سایتت تو داینامیک بودن لنگ میزنه

KavoshGar_ir
شنبه 25 اردیبهشت 1389, 12:44 عصر
اگر روی اینترنت سرچ کنی مقالات زیادی پیدا میکنی ... کافیه کیورد های لاتین این موضوع را سرچ کنی

مقاله زیر را دنبال کن احتمالا به جواب میرسی ...

راه حل کلیش استفاده از Theme And Skins تعبیه شده در ASP.NET ....

مقاله مشابه:


Step 1 - ChangeThemeControl.ascx

Create a user control that will have links of different themes and a simple JavaScript function named ChangeTheme(theme, themeName) that will take two parameter.

theme: This is the path of the .css file that will be used to temporarily set the theme of the page from which you have opted to change the theme.

themeName: This is the actual theme name that you have created in App_Themes folder of your root directory.

Put one <iframe> on this user control. This iframe will be used to pass the theme name as a querystring to ChangeThemeHidden.aspx page (described next) when you click on different theme icons/links.

The major code of this usercontrol is
<hr />

Change theme: <a href="#" onclick="javascript:ChangeTheme('/theme1/theme1.css', 'theme1')">Theme 1</a> |

<a href="#" onclick="javascript:ChangeTheme('/theme2/theme2.css', 'theme2')">Theme 2</a>

<hr />

<asp:Label ID="Label1" runat="server"></asp:Label>




<iframe id="magicFrame" width="0" height="0" style="display:none;"></iframe>




<script language="javascript" type="text/javascript">

function ChangeTheme(theme, themeName)

{

var cssid = document.getElementsByTagName("link");

var css = '';

for (var j = 0; j < cssid.length ; j++)

{

if (cssid[j].type == 'text/css') // search only css link

{

cssid[j].href = "/App_Themes"+ theme;



css = cssid[j].href;

}

}



document.getElementById('magicFrame').src = 'ChangeThemeHidden.aspx?theme='+ themeName;



}

</script>


Step 2 - ChangeThemeHidden.aspx

Create a separate page ChangeThemeHidden.aspx that will contain nothing but a Page_Load event.

This Page_Load event will check for a querystring called theme, if it will find this querystring then it will write its value to the session variables Session["GlobalSessionTheme"]. This session variable will be used to persist the theme name for that particular user who is visiting your site.

The code of this file is
protected void Page_Load(object sender, EventArgs e)

{

if (Request["theme"] != null)

{

WriteTheme(Request["theme"].ToString());

}

}




private void WriteTheme(string theme)

{

Session["GlobalSessionTheme"] = theme;

}


Step 3 - ChangeTheme.aspx & ChangeTheme2.aspx

Just create two sample pages to see that your code is working fine and selected theme is persisting even if user is navigating from one page to another. On this page, just register the usercontrol that you created in the first step, this will give option to the user to select different themes from any page of the site.

These pages may contain anything you need on it. In addition to your own code you will need to write following event to make sure that you are rendering the page with the theme that was selected by user.

The code to do this is
protected override void OnPreInit(EventArgs e)

{

if (Session["GlobalSessionTheme"] != null)

this.Theme = Session["GlobalSessionTheme"].ToString();

}



Step 4 - Theme1.css, Theme2.css

Create your .css files for different themes. I have create two files with different background & foreground color of the page.

Theme1.css
body

{

background-color:yellow;



font-size:10pt;

color:Blue;

}




a

{

font-weight:bold;

color:Green;

}


Theme2.css
body

{

background-color:C#‎0d0e0;



font-size:10pt;

color:Maroon;

}




a

{

font-weight:bold;

color:blue;

}




Step 5 - Just test it!!!
منبع:
Change theme dynamically without page refresh in ASP.NET (http://tipsstation.com/article/Change-theme-dynamically-without-page-refresh-in-ASP-Dot-NET.aspx)
Themes and Skins in ASP.Net (http://sharpertutorials.com/themes-and-skins-in-aspnet/)