Tuesday, December 29, 2009

.net join for arrays

If you're used to the old way of converting an array into a comma delimited list, here's the new way(?). It's been there, but you may not have used it.

String.Join(",", array);

How do I add Head tags in .net using c#

There are of course many tags you can use. Here are a couple to get you started... Also, don't forget to set the Title as well. (this.Header.Title = "this is the title";)

  1. keywords
  2. description
  3. robots
  4. date


HtmlMeta metatag = new HtmlMeta();
metatag.Name = "Description";
metatag.Content = "Here's a great description.";
this.Header.Conrols.Add(metatag);

OR, I like it this way...


HtmlMeta metatag = new HtmlMeta(){

   Name = "Description",
   Content = "Here's a great description.",
};

this.Header.Conrols.Add(metatag);

Friday, December 18, 2009

How do I urlencode in an aspx file

I ran across this while using a repeater. Of course, it can occur in a datagrid as well. The data that's coming from the datasource has & signs and spaces. When the & comes across, and it's put into a query string as a parameter, it's not translated right when sent to the next page. So, I want to encode it so the request.querystring will work. Here's the solution:


Tuesday, December 15, 2009

type of conditional expression cannot be determined because there is no implicit conversion between null and bool

Have you seen this?
Type of conditional expression cannot be determined because there is no implicit conversion between null and bool

I received this because I was doing an inline if statement (ternary I think) setting the value to a boolean. The boolean value I was setting was nullable. And, because I did want to set the value to null in some cases, this error was showing. To fix it, I just did the following (bool?)null. Then it all worked out

Friday, December 4, 2009

Favorite Visual Studio shortcut keys

Stop Debugging: SHIFT + F5
View code in full screen mode: ALT + SHIFT + ENTER
Go to Definition: F12
Close Window: CTRL + F4

Thursday, December 3, 2009

Telerik RadWindow Clicking on the link doesn't do anything

Not sure if you encountered this before. Essentially, when using the Telerik RadControls RadWindow, specifically in this case the RadWindowManager and trying to use a modal window, there is an assumption I didn't realize. When you update your OpenerElementID you are supposed to set it to the id of the control whether it's a link, linkbutton, whatever. Well, initially, I set this to the ID of the control. In reality, it must be the actual ID of the control. To get this, load your page, then get the name via the HTML source.

Wednesday, December 2, 2009

How to get the date in a sql statement (TSQL)

To get the date in a select statement, stored procedure, etc. You can use the getdate() function.
For example, you can do

Select getdate()

Getting the word out about this site

Ok, here's where we get a little bit selfish. But, wanted to get more traffic, so we added ourselves to yousaytoo.com. If you want to know more about it go here:

Make Money Blogging

Monday, November 30, 2009

Difference between System.DateTime.Now and System.DateTime.Today

Per Microsoft:
Because it returns the current date without the current time, the Today property is suitable for use in applications that work with dates only. For details, see Choosing Between DateTime, DateTimeOffset, and TimeZoneInfo. In contrast, the TimeOfDay property returns the current time without the current date, and the Now property returns both the current date and the current time.

Wednesday, November 25, 2009

How do you add drop down items to a drop down which uses a datasource

Ran into this the other day. I'm filling a drop down (combo box) from the code behind using a datasource. But, the data source of course doesn't include a default or empty value for the top of the list. So, what do you do?

What you can do is on the aspx file add the attribute AppendDataBoundItems="true".
Once you have added this attribute to the drop down (combo box), you can add a new drop down item to the combo box.
Example:

Monday, November 23, 2009

does not contain a definition for 'RadGridTradeOrders_NeedDataSource' and no extension method 'RadGridTradeOrders_NeedDataSource'

I fixed this by going into the code behind of the aspx file and removed the line: onneeddatasource="RadGridTradeOrders_NeedDataSource"

I think this occurred because I was editing the a radgrid control by changing the data field name. Because my datasource was dynamic, changing this field caused the attribute above to be added automatically.

NOTE: I also believe that making custom changes in the source code (aspx) for this control causes unnecessary issues. Therefore, I would recommend using the design view to set properties on the telerik controls.

Sunday, November 22, 2009

ASP.NET RSS Toolkit

Research: "ASP.Net RSS Toolkit gives ASP.Net applications the ability to consume and publish to RSS feeds.


Features include:
RssDataSource control to consume feeds in ASP.NET applications
Works with ASP.NET data bound controls
Implements schema to generate columns at design time
Supports auto-generation of columns at runtime (via ICustomTypeDescriptor implementation)
Caching of downloaded feeds both in-memory and on-disk (persisted across process restarts)
Generation of strongly typed classes for feeds (including strongly typed channel, items, image, handler) based on a feed URL (the toolkit recognizes RSS, Atom and RDF feeds) or a file containing a sample feed. Allows programmatically download (and creation) of feeds using strongly-typed classes."

Reference: ASP.NET RSS Toolkit

RssFeed

Research: "RssFeed is an open source custom ASP.NET server control that displays the contents of a specified RSS feed in an ASP.NET web page. This control was developed by Scott Mitchell in October 2003. You can see RssFeed in action at the Recommended Blogs section on 4GuysFromRolla.com. There are also some live demos of RssFeed with complete source available."
Reference: RssFeed

ASP 101 - An ASP.NET RSS Feed Reader

Research: An ASP.NET RSS Feed Reader
If I was going to go through the trouble of doing this in ASP.NET, I was going to do it right and, while it is possible, I didn't want to call the COM objects that we used the first time around. This is .NET after all so naturally I wanted to use the .NET Framework's XmlDocument object. Aside from using the .NET object, this part of the script is basically the same. We create an XML object and load an XML file into it either from the remote server or from the file system."
Read More: ASP 101 - An ASP.NET RSS Feed Reader

Reading RSS Feeds with .NET

Research: "RSS feed reader
A custom RSS Feed Reader can be developed in ASP.NET 2.0 targeting the feed: http://localhost/RSSFeeds/EmployeeDetails.aspx
ASP.NET 2.0
1. Open Microsoft Visual Studio 2005 and create a 'Web Site' with name RSSFeedReader. After the project is created, right click on the project node and click on 'Add New Item'.
2. In the 'Add New Item' dialog box, select 'Web Form' and enter the name RSSRead.aspx in the 'Name' area and click on Add.
3. Open the 'Source' view of RSSRead.aspx."

Read More: Publishing And Reading RSS Feeds In ASP.NET

Tuesday, November 17, 2009

How do I loop through an enum

It is so easy to create enums and reuse them in multiple projects. You can use them in many places, one of the most common is to use them in drop down lists. Here, we'll show you how to create an enum, how to access the values using a foreach, then how to use an enum to fill a drop down list in c#.

First, make sure you have an enum defined:

public enum DaysOfTheWeek

{
 Monday,
 Tuesday,
 Wednesday,
 Thursday,
 Friday,
 Saturday,
 Sunday
}

Now that we have an enum, we would want to loop through it.

foreach(int value in System.Enum.GetValues(typeof(DaysOfTheWeek)))

  //To access the index (0,1,2,3,4,5,6) use the variable value stated above
  int intIndex = value;
 //To access the text of the index, get the names
  string strName = System.Enum.GetName(typeof(DaysOfTheWeek), value)
}
An example of filling a drop down list with enum values using the information above:

foreach(int value in System.Enum.GetValues(typeof(DaysOfTheWeek)))

{
  //Create the lineitem so we can add it to an existing dropdown
  ListItem liDay = new ListItem();

  //To access the index (0,1,2,3,4,5,6) use the variable value stated above

  liDay.Value = value.ToString();
 
  //To access the text of the index, get the names
  liDay.Text = System.Enum.GetName(typeof(DaysOfTheWeek), value)

  //Add it to the drop down
  ddlDaysOfTheWeek.Items.Add(liDay);

}







Wednesday, October 21, 2009

How do I add a theme to web.config file

In the web.config file, look for the pages tag under web.config. Within the pages tag add the attribute "theme", then type in the name of your theme.


Here's an example:



    

Saturday, August 29, 2009

Part Time Webmaster Launch

We've launched another site. It's called Parttimewebmaster.com. Here, we discuss a random listing of events and topics that may come up about websites. Feel free to comment, post, whatever. Right now, we have a forum area as well to review topics on open source software, hosting or search engines, etc.

Saturday, August 1, 2009

New Site launch! Jahbs.com

We have launched a new site called jahbs.com. Here you can network with other professionals in your field, review jobs, write a blog, post pages, etc.

The BIG benefit and difference between this site and other sites is the following:
1. You can add Google Adsense code to your profile. When you post to your blog, your adsense code will display at the end of your blog. What does this mean. It means that each time you post a blog entry, you gain the chance of making money from Google ads.
2. You can post job opportunities online for FREE.

Monday, July 20, 2009

xslt exists - Why can't I use it?

If you're looking to use the exists function for xslt and you can't figure out why it is a function that doesn't exist, there is a workaround. Instead of using try using This is the alternative workaround.

Friday, June 19, 2009

My date timestamps off by a day

Try and test this, but only during the summer months. Create a new record in your database that requires a timestamp. Is the time off by an hour? If so, you are probably dealing with international times.

What's happening is the local time is different than the international time for the US due to the fact we have daylight savings. Here in the US, the time changes, but to the rest of the world, it doesn't. Note, you may only notice this in the summer. During the winter months, you will not see this error.

Wednesday, April 15, 2009

replace is an unknown xslt function

I'm working client side and found that I couldn't use the replace function in the xslt value arguments. For all of those looking for a workaround, you can use the translate function. To find out more, please visit http://www.w3.org/TR/xpath#function-translate

Monday, February 23, 2009

Making extra money as a programmer on the side

Ok, I've been programming for years, so not much shocks me anymore. But, every once in a while I wonder how I can make more money without having to work more hours. At some points, it seems as though, as a developer, I may spend the rest of my life in "crisis mode" for clients.

Anyway, lately, I've been investigating some strategies. I've found that if I were to choose the ultimate job, it would consist of the following... unlimited number of clients, make money when I'm not working, create residual money, no extreme deadlines.

From what I've seen so far, it looks like affiliate marketing is the way to go. I've been working with it for a short time now. No big successes yet. But, considering this economy, companies are scrambling for these marketers.

If you want to continue on that journey with me, or learn more, please visit http://www.awealthyaffiliatemember.com for more information. On a side note, the group within this "university" also needs developers as they have their own job board.

Thursday, February 19, 2009

How can I tell if a stored procedure is taking too long to run

A lot of times, we are called in a panic if something crashes. A lot of times, it could be because something crashed, in some cases, a stored procedure. Here is a good article with a solution: http://www.databasejournal.com/features/mssql/article.php/3500276/Identifying-Long-Running-SQL-Server-Agent-Jobs.htm

Thursday, February 12, 2009

A severe error occurred on the current command. The results, if any, should be discarded.

Error message:
A severe error occurred on the current command. The results, if any, should be discarded.
A severe error occurred on the current command. The results, if any, should be discarded.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: A severe error occurred on the current command. The results, if any, should be discarded.
A severe error occurred on the current command. The results, if any, should be discarded.

Error Message in DB:
The connection has been dropped because the principal that opened it subsequently assumed a new security context, and then tried to reset the connection under its impersonated security context. This scenario is not supported. See "Impersonation Overview" in Books Online

Solution:
Implement coding workaround, non-dba issue.
Issue: Web.config setting for connection strings "Connection Reset" does not work for newer versions of .NET2.0. This issue starts once .NET 2.0 SP1 or greater is installed on the application server machine. You'll have to change your code where you are impersonating someone.

Immediate solution:
In your web.config database connection string turn off pooling, Pooling=false;