The code below will set the forecolor or font color of a control, such as a
label, to white or black, depending on the background
color.
System.Drawing.Color foreColor =
System.Drawing.Color.Black;
// all colors coming in are in Hex
format. No Known colors but we'll check anyway.
int r;
int
g;
int b;
if (backColor.IsKnownColor)
{
r = backColor.R;
g = backColor.G;
b = backColor.B;
}
else
{
r =
int.Parse(backColor.ToString().Substring(8, 2),
System.Globalization.NumberStyles.HexNumber);
g =
int.Parse(backColor.ToString().Substring(10, 2),
System.Globalization.NumberStyles.HexNumber);
b =
int.Parse(backColor.ToString().Substring(12, 2),
System.Globalization.NumberStyles.HexNumber);
}
int
changeToWhite = 0;
if (r <= 128)
{
changeToWhite ++;
}
if (g <= 128)
{
changeToWhite ++;
}
if (b <=
128)
{
changeToWhite ++;
}
if
(changeToWhite > 2)
{
foreColor =
System.Drawing.Color.White;
}
Thursday, December 22, 2011
Tuesday, October 18, 2011
Using AJAX in a SharePoint webpart - UpdatePanel control
To take advantage of AJAX and partial page rendering in a SP2010 webpart, add
your radio button, dropdown list, etc. controls to an UpdatePanel for a better
user experience.
The CGCC-Parent.master file already contains the ScriptManager control so there is no need to add this to your webpart.
1. Create an instance of the panel. Set the UpdateMode to conditional.
updatePanel2 = new UpdatePanel();
updatePanel2.UpdateMode = UpdatePanelUpdateMode.Conditional;
2. Add your controls to the updatePanel. Make sure you add the controls to the ContentTemplateContainer.
updatePanel1.ContentTemplateContainer.Controls.Add(creditRadio);
updatePanel1.ContentTemplateContainer.Controls.Add(creditRequired);
updatePanel1.ContentTemplateContainer.Controls.Add(campusQ1);
updatePanel1.ContentTemplateContainer.Controls.Add(creditCheckBox);
3. Finally, and add your panel to the list of controls.
Controls.Add(updatePanel1);
The CGCC-Parent.master file already contains the ScriptManager control so there is no need to add this to your webpart.
1. Create an instance of the panel. Set the UpdateMode to conditional.
updatePanel2 = new UpdatePanel();
updatePanel2.UpdateMode = UpdatePanelUpdateMode.Conditional;
2. Add your controls to the updatePanel. Make sure you add the controls to the ContentTemplateContainer.
updatePanel1.ContentTemplateContainer.Controls.Add(creditRadio);
updatePanel1.ContentTemplateContainer.Controls.Add(creditRequired);
updatePanel1.ContentTemplateContainer.Controls.Add(campusQ1);
updatePanel1.ContentTemplateContainer.Controls.Add(creditCheckBox);
3. Finally, and add your panel to the list of controls.
Controls.Add(updatePanel1);
Thursday, September 22, 2011
More on the TextBox Counter by SKMControls
I found a free TextBox counter by SKMControls that
counts the amount of characters in a multiline asp:TextBox control. This is
useful for Asp.NET pages with Note fields where end users tend to write alot but
yet you have limits to how many characters the database field will hold.
First add the file skmcontrols2.dll to the bin folder.
In your aspx .NET page, register the control.
<% @ Register Assembly="skmControls2" Namespace="skmControls2" TagPrefix="skm" %>
Next, add your control to the page.
<skm:TextBoxCounter runat="server" ForeColor="GrayText" WarningPercentage="80" MaxCharacterLength="7900" TextBoxControlId="NoteTextBox" ID="TextBoxCounter1"></skm:TextBoxCounter>
The TextBoxControlID property is used to bind the control to the multi-line textbox on your page.
First add the file skmcontrols2.dll to the bin folder.
In your aspx .NET page, register the control.
<% @ Register Assembly="skmControls2" Namespace="skmControls2" TagPrefix="skm" %>
Next, add your control to the page.
<skm:TextBoxCounter runat="server" ForeColor="GrayText" WarningPercentage="80" MaxCharacterLength="7900" TextBoxControlId="NoteTextBox" ID="TextBoxCounter1"></skm:TextBoxCounter>
The TextBoxControlID property is used to bind the control to the multi-line textbox on your page.
Tuesday, July 26, 2011
Using the asp:ListView control in SharePoint
Below is example code implementing the asp:ListView control in a SharePoint
page. Bound data comes from the SPDataSource control.
The SelectCommand is in the CAML query language which is XML based. The query looks for all Calendar events ending today or later, row limit of 4, sorted by start date. You can also use parameters for a dynamic SelectCommand:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spdatasource.selectparameters.aspx
<asp:ListView ID="ListView1" runat="server" DataSourceID="spDataSource1">
<LayoutTemplate>
<div style="background-color: #fffddd; padding: 10px; width: 200px">
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</div>
</LayoutTemplate>
<ItemTemplate>
<p style="font-size:small;">
<a href="/examples/Lists/Events//DispForm.aspx?ID=<%# Eval("ID") %>" style="color:#787878"><span style='text-decoration:none;<%# Eval("Category").Equals("Holiday") ? "font-weight:bold" : "font-weight:normal" %>'><%# Eval("DisplayDateTime").ToString().Substring(8) %></span><br />
<span style="font-style:italic"><%# Eval("Title") %></span></a></p>
</ItemTemplate>
</asp:ListView>
<SharePointWebControls:SPDataSource runat="server" ID="spDataSource1" DataSourceMode="List" SelectCommand="<Query><Where><Geq><FieldRef Name='EndDate' /><Value Type='DateTime'><Today /></Value></Geq></Where><OrderBy><FieldRef Name='EventDate' Ascending='True' /></OrderBy><RowLimit>4</RowLimit></Query>">
<SelectParameters> <asp:Parameter Name="WebUrl" DefaultValue="/examples/" /> <asp:Parameter Name="ListName" DefaultValue="Events" /> </SelectParameters>
</SharePointWebControls:SPDataSource>
The SelectCommand is in the CAML query language which is XML based. The query looks for all Calendar events ending today or later, row limit of 4, sorted by start date. You can also use parameters for a dynamic SelectCommand:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spdatasource.selectparameters.aspx
<asp:ListView ID="ListView1" runat="server" DataSourceID="spDataSource1">
<LayoutTemplate>
<div style="background-color: #fffddd; padding: 10px; width: 200px">
<asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
</div>
</LayoutTemplate>
<ItemTemplate>
<p style="font-size:small;">
<a href="/examples/Lists/Events//DispForm.aspx?ID=<%# Eval("ID") %>" style="color:#787878"><span style='text-decoration:none;<%# Eval("Category").Equals("Holiday") ? "font-weight:bold" : "font-weight:normal" %>'><%# Eval("DisplayDateTime").ToString().Substring(8) %></span><br />
<span style="font-style:italic"><%# Eval("Title") %></span></a></p>
</ItemTemplate>
</asp:ListView>
<SharePointWebControls:SPDataSource runat="server" ID="spDataSource1" DataSourceMode="List" SelectCommand="<Query><Where><Geq><FieldRef Name='EndDate' /><Value Type='DateTime'><Today /></Value></Geq></Where><OrderBy><FieldRef Name='EventDate' Ascending='True' /></OrderBy><RowLimit>4</RowLimit></Query>">
<SelectParameters> <asp:Parameter Name="WebUrl" DefaultValue="/examples/" /> <asp:Parameter Name="ListName" DefaultValue="Events" /> </SelectParameters>
</SharePointWebControls:SPDataSource>
Thursday, July 21, 2011
Creating an SPDataSource .NET control
To use an SP List as a data source for a .NET web control, declare an
SPDataSource as shown:
<SharePointWebControls:SPDataSource runat="server" ID="spDataSource1" DataSourceMode="List" SelectCommand="<Query><Where><Eq><FieldRef Name='Section'/><Value Type='Choice'>Get Started</Value></Eq></Where><OrderBy><FieldRef Name='SortOrder' Ascending='True' /></OrderBy></Query>">
<SelectParameters> <asp:Parameter Name="WebUrl" DefaultValue="/student-affairs/enrollment/" /> <asp:Parameter Name="ListName" DefaultValue="Transfer" /> </SelectParameters>
</SharePointWebControls:SPDataSource>
The SelectCommand property allows for filtering and sorting of results.
The ID for this data source will then go inot the DataSourceID field of the web control that uses the SP List, as shown below:
<asp:GridView ID="DataGrid1" runat="server" DataSourceID="spDataSource1">
...
</asp:GridView>
<SharePointWebControls:SPDataSource runat="server" ID="spDataSource1" DataSourceMode="List" SelectCommand="<Query><Where><Eq><FieldRef Name='Section'/><Value Type='Choice'>Get Started</Value></Eq></Where><OrderBy><FieldRef Name='SortOrder' Ascending='True' /></OrderBy></Query>">
<SelectParameters> <asp:Parameter Name="WebUrl" DefaultValue="/student-affairs/enrollment/" /> <asp:Parameter Name="ListName" DefaultValue="Transfer" /> </SelectParameters>
</SharePointWebControls:SPDataSource>
The SelectCommand property allows for filtering and sorting of results.
The ID for this data source will then go inot the DataSourceID field of the web control that uses the SP List, as shown below:
<asp:GridView ID="DataGrid1" runat="server" DataSourceID="spDataSource1">
...
</asp:GridView>
Tuesday, April 26, 2011
Adding a stylesheet to a SharePoint masterpage using the CSSRegistration control
Sharepoint has a .NET control for registering CSS files in a SharePoint
masterpage called SharePoint:CSSRegistration. Use the ~Site token to specify the
current site. This control goes in the head section of the
masterpage.
<SharePoint:CssRegistration name="<% $SPUrl:~Site/CSS/gilariver.css%>" runat="server"/>
New to SharePoint 2010
You can specify the order using the After property. The After property contains the name of the CSS that you want to place the CSS after. The ConditionalExpression parameter will tell the CssLink to render the Conditional-CSS code as well as the CSS link.
<SharePoint:CssRegistration name="<% $SPUrl:~Site/CSS/gilariver.css%>" runat="server"/>
New to SharePoint 2010
You can specify the order using the After property. The After property contains the name of the CSS that you want to place the CSS after. The ConditionalExpression parameter will tell the CssLink to render the Conditional-CSS code as well as the CSS link.
Using the RadCaptcha control
RadControls has a RadCaptcha control that can be used in .NET applications or
SharePoint web parts. Add the RadCaptcha image handler to the web.config file to
use the captcha:
<system.webServer>
...
<handlers>
...
<add name="Telerik.Web.UI.WebResource" path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2010.3.1317.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" />
...
</handlers>
</system.webServer>
<system.webServer>
...
<handlers>
...
<add name="Telerik.Web.UI.WebResource" path="Telerik.Web.UI.WebResource.axd" verb="*" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2010.3.1317.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4" />
...
</handlers>
</system.webServer>
Wednesday, April 6, 2011
SharePoint List displayed in XML using OWSSVR.dll
OWSSVR.dll will, among other functions, return the XML data of a SharePoint
List. The format of this utility
is:
http://yourserver/yourweb/_vti_bin/owssvr.dll?Cmd=Display&List={guid}&XMLDATA=TRUE
http://webcs10.cgc.maricopa.edu/student-affairs/athletics/athletics/_vti_bin/owssvr.dll?Cmd=Display&List=5C1E1425%2D8F8E%2D4427%2D8B4A%2D1A97748B4AD6&XMLDATA=TRUE
More information can be found here:
http://msdn.microsoft.com/en-us/library/ms478653.aspx
http://yourserver/yourweb/_vti_bin/owssvr.dll?Cmd=Display&List={guid}&XMLDATA=TRUE
http://webcs10.cgc.maricopa.edu/student-affairs/athletics/athletics/_vti_bin/owssvr.dll?Cmd=Display&List=5C1E1425%2D8F8E%2D4427%2D8B4A%2D1A97748B4AD6&XMLDATA=TRUE
More information can be found here:
http://msdn.microsoft.com/en-us/library/ms478653.aspx
Tuesday, January 4, 2011
Dynamically changing Frameset dimensions
There may be a need to dynamically change the dimensions of an HTML Frameset in
the DigitalSignage system.
If we have a frameset defined:
<frameset id="mainFrame" border="0" rows="25%,70%,*">
<frame border="0" noresize="noresize" src="header.html" />
<frame src="" scrolling="no" frameborder="0" />
<frameset border="0" cols="25%,50%,*">
<frame src="footer1.html" scrolling="no" frameborder="0" />
<frame src="footer2.html" scrolling="no" frameborder="0" />
<frame src="weather.aspx" scrolling="no" frameborder="0" />
</frameset>
</frameset>
Below is an example of javascript that varies the dimensions of the rows:
parent.document.getElementById('mainFrame').rows='0%,95%,*';
With this code we're hiding the top row by setting the height to 0%.
If we have a frameset defined:
<frameset id="mainFrame" border="0" rows="25%,70%,*">
<frame border="0" noresize="noresize" src="header.html" />
<frame src="" scrolling="no" frameborder="0" />
<frameset border="0" cols="25%,50%,*">
<frame src="footer1.html" scrolling="no" frameborder="0" />
<frame src="footer2.html" scrolling="no" frameborder="0" />
<frame src="weather.aspx" scrolling="no" frameborder="0" />
</frameset>
</frameset>
Below is an example of javascript that varies the dimensions of the rows:
parent.document.getElementById('mainFrame').rows='0%,95%,*';
With this code we're hiding the top row by setting the height to 0%.
Subscribe to:
Posts (Atom)