Get current child SITE ID in a module. How?

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
8/10/2009 11:57:13 AM
Gravatar
Total Posts 221

Get current child SITE ID in a module. How?

Hello, I built a very simple Flash photo banner rotator module that consists of just the .ascx file and then a few settings pulled in the feature settings area. Works good, very simple.

One of the settings the user needs to change is to enter the folder where the images should pull from. What I would like to do is only make the user enter the folder from their file area forward and not have to enter the whole beginning of the path /data/sites/3/....

Note the bold code below:  How can I prepopulate the module below to grab the current SITE ID and place it in my code below?

 

<%@ Control Language="C#" ClassName="BannerRotator.ascx" Inherits="mojoPortal.Web.SiteModuleControl" %>
<%@ Import Namespace="mojoPortal.Business" %>
<%@ Import Namespace="mojoPortal.Business.WebHelpers" %>
<%@ Import Namespace="mojoPortal.Web.Framework" %>
<%@ Import Namespace="mojoPortal.Web.Controls" %>
<%@ Import Namespace="mojoPortal.Web.Editor" %>
<%@ Import Namespace="mojoPortal.Net" %>

<portal:ModuleTitleControl id="Title1" runat="server" />
<asp:Panel ID="pnlMyClass" runat="server" EnableViewState="false" CssClass="modulecontent">

<script type="text/javascript" src="_Include/swfobject/swfobject.js"></script>
<div id="BannerRotator"></div>
<script type="text/javascript">
var so = new SWFObject("_Custom/Modules/BannerRotator/preview.swf", "preview", "<%Response.Write(Settings["Width"].ToString());%>", "<%Response.Write(Settings["Height"].ToString());%>", "7", "#333333");
so.addVariable("dataFile", "_Custom/Modules/BannerRotator/auto.asp?Path=/Data/Sites/3/<%Response.Write(Settings["ImagePath"].ToString());%>");
so.addVariable("SlideDuration", "<%Response.Write(Settings["SlideDuration"].ToString());%>");
so.addVariable("SlideWidth", "<%Response.Write(Settings["Width"].ToString());%>");
so.addVariable("SlideHeight", "<%Response.Write(Settings["Height"].ToString());%>");
so.addParam("wmode", "transparent");
so.write("BannerRotator");
</script>

</asp:Panel>

8/10/2009 12:14:23 PM
Gravatar
Total Posts 18439

Re: Get current child SITE ID in a module. How?

There is a siteSettings object intrinsicly available in SiteModuleControl so you can use siteSettings.SiteID, however if it were me I would not access those objects directly in your Response.Write, I would use a script with runat=Server, I would declare protected variables and in page load event set those variables to the values you need then use the variables in Response.Write().

And actually you can abbreviate the Response.Write as just =, so instead of  

<%Response.Write(someVariable);%>

you can use the more simple <%= someVariable %>

where someVariable is a variable declared as protected or public in the server side code.

Hope it helps,

Joe

8/10/2009 12:46:19 PM
Gravatar
Total Posts 221

Re: Get current child SITE ID in a module. How?

Very nice: this did work for returning the SITE ID: Thank you!!

<%=siteSettings.SiteId.ToString()%>

 

I'm a newbie .NET, so thank you for the advice on the programming. That does make more sense I'm sure (I'm so used to classic asp). But when I try this as way of a test I get the error: CS0103: The name 'strSiteID' does not exist in the current context

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
String strSiteID = siteSettings.SiteId.ToString();
}
</script>

<%=strSiteID%>
 

But no need to teach basic programming here, I'm sure to figure it out in time :)

 

8/10/2009 12:48:49 PM
Gravatar
Total Posts 18439

Re: Get current child SITE ID in a module. How?

declare the variable outside of the page load event

protected string strSiteID = string.Empty;

protected void Page_Load(object sender, EventArgs e)
{
strSiteID = siteSettings.SiteId.ToString();
}

Hope it helps,

Joe

 

8/10/2009 12:57:11 PM
Gravatar
Total Posts 221

Re: Get current child SITE ID in a module. How?

Nice, that works.  *little .net lightbuld in head starts to faintly flicker

God I'm envious of people who make it look so easy! You should build your own CMS or something! :)

8/10/2009 1:39:20 PM
Gravatar
Total Posts 18439

Re: Get current child SITE ID in a module. How?

Hey Eric,

Thanks for the beer!

Cheers,

Joe 

You must sign in to post in the forums. This thread is closed to new posts.