Microsoft Most Valuable Professional

Chris Pietschmann

An MVP From Wisconsin

My new website is coming soon!

An new year and a new look for PietschSoft.com is coming!

I am currently working on a new website for PietschSoft.com. My blog isn't going anywhere. Since it is the main content of my site I am making it the center of my site. I am working on making existing URL's for my blog still work with the new site. But, I'm not sure if I'll maintain compatibility for the URL of the RSS feeds.

For any of you who are consuming the RSS feeds; they may break when I launch the new site. If any of them do; please visit http://pietschsoft.com for the new RSS feed URL.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General
Posted by crpietschmann on Friday, December 30, 2005 10:12 PM
Permalink | Comments (0) | Post RSSRSS comment feed


ASP.NET 2.0: How to get a specific ConnectionString from the Web.Config by name

You have your ConnectionString for your ASP.NET web app stored in the Web.Config file. Now how exactly how do you get that ConnectionString out of there from within your code?

Sample Web.Config section with a ConnectionString:

[code:xml]
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=myDBServer;database=myDB;Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
[/code]

Now lets get the ConnectionString from the Web.Config file with only one line of code:

[code:c#]
string strConnString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
[/code]

VB:
Dim strConnString As String = ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString

Now isn't that simple? I'm posting this because I did a search and didn't find an example of how to do this. I had to poke around a little and discover this on my own. I hope this helps someone avoid some frustration.

Currently rated 4.6 by 8 people

  • Currently 4.625/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: General
Posted by crpietschmann on Wednesday, December 28, 2005 11:18 PM
Permalink | Comments (11) | Post RSSRSS comment feed


ASP.NET 2.0 Client Callbacks inside a User Control

Implementing Client Callbacks (AJAX) in ASP.NET 2.0 is actually really simple to do as long as you know a little JavaScript. Heres is a small example of using a Client Callback from within a User Control. I've tested this example with IE6 and Firefox 1.5

1 <%@ Control Language="VB" ClassName="ClientCallbackControl"%> 2 <%@ Implements Interface="System.Web.UI.ICallbackEventHandler"%> 3 <script runat="server"> 4 ''This is the variable that holds the client callback 5 ''results that will be returned to the client. 6 Dim MyCallbackResult As String 7 8 ''This is the server-side function that is called when the 9 ''client callback results are returned to the browser. 10 Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult 11 Return MyCallbackResult 12 End Function 13 14 ''This is the server-side function that is called when the 15 ''client callback is fired off. 16 Public Sub RaiseCallbackEvent(ByVal eventArgument As String) Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent 17 MyCallbackResult = Now.ToString 18 End Sub 19 20 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 21 ''Get Client Side ID of this instance of the User Control 22 ''This will be used to Prefix all the JavaScript functions 23 ''this control uses so that you can have multiple instances 24 ''of this control on the same page. 25 Dim strJSCallbackPrefix As String = Me.ClientID 26 27 ''Get the JavaScript that will callback to the server 28 Dim cm As ClientScriptManager = Page.ClientScript 29 Dim cbReference As String 30 cbReference = cm.GetCallbackEventReference(Me, _ 31 "arg", _ 32 strJSCallbackPrefix & "ReceiveServerData", _ 33 "context") 34 35 ''Declare the function that will be called to fire off a 36 ''client callback to the server. 37 Dim callbackScript As String = _ 38 "function " & strJSCallbackPrefix & "CallServer(arg, context){" & cbReference & "; }" 39 cm.RegisterClientScriptBlock(Me.GetType(), strJSCallbackPrefix & "CallServer", callbackScript, True) 40 41 ''Declare the function that will recieve the client callback 42 ''results from the server. 43 Dim strReceiveServerData As String = _ 44 "function " & strJSCallbackPrefix & "ReceiveServerData(arg, context){context.innerHTML = arg;}" 45 cm.RegisterClientScriptBlock(Me.GetType, strJSCallbackPrefix & "ReceiveServerData", strReceiveServerData, True) 46 47 48 ''Set the JavaScript that is run when the button is clicked 49 ''This sends the context of lblMessage1 so that the 50 ''ReceiveServerData function can change its value to what is 51 ''returned from the server. 52 Button1.OnClientClick = _ 53 strJSCallbackPrefix & "CallServer(1, document.getElementById('" & lblMessage1.ClientID & "')); " & _ 54 "return false;" 55 56 57 ''Load lblMessage1 with it's value on initial load of the page. 58 RaiseCallbackEvent(1) 59 lblMessage1.Text = GetCallbackResult() 60 End Sub 61 </script> 62 <asp:Button ID="Button1" runat="server" Text="Get DateTime Stamp" /> 63 &nbsp;&nbsp; 64 <asp:Label runat="server" ID="lblMessage1"></asp:Label>

Currently rated 3.3 by 3 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: General
Posted by crpietschmann on Saturday, December 10, 2005 2:10 PM
Permalink | Comments (11) | Post RSSRSS comment feed


T-SQL: Join Tables by a Field that contains a delimited string

This is the first time I ran into a situation where I needed to Join two tables (one with a varchar field and one with a varchar field that contains pipe delimited data) so I decided to post it for other who may not know you can do this. Below is a simplified example with solution of getting all rows of the first table whos values are contained in the pipe delimited field of the second table. This is really simple to do and you don't even have to use any User-Defined Functions or Cursors to do it. And I'm sure that not all of you who may read this know that you can use LIKE in a JOIN.

1 SELECT City
2 FROM Table1
3 JOIN Table2 ON Table2.CityList LIKE '%' + Table1.City + '%'


Table1
City varchar(30)

Table1 Sample Data
West Bend
Kewaskum
Hartford

Table2
CityList varchar(2000)

Table2 Sample Data
West Bend|Kewaskum
Kewaskum
Hartford

 

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: General
Posted by crpietschmann on Friday, December 09, 2005 6:16 PM
Permalink | Comments (0) | Post RSSRSS comment feed

.NET Framework - Check if Windows booted in Normal or Safe Mode

Heres a really small code sample on how to check which mode Windows was booted up in (Normal or Safe Mode). This works in .NET 1.x and 2.0.

  1 'This code checks to see which mode Windows has booted up in.
  2 Select Case System.Windows.Forms.SystemInformation.BootMode
  3 Case BootMode.FailSafe
  4      'The computer was booted using only the basic files and drivers.
  5      'This is the same as Safe Mode
  6 Case BootMode.FailSafeWithNetwork
  7      'The computer was booted using the basic files, drivers, and services necessary to start networking.
  8      'This is the same as Safe Mode with Networking
  9 Case BootMode.Normal
10      'The computer was booted in Normal mode.
11 End Select

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General
Posted by crpietschmann on Friday, December 09, 2005 2:13 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Video Game Music on Piano!

Ever wanted to hear your favorite video game music played on piano?

http://www.videogamepianist.com./index.php?id=audio

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: General
Posted by crpietschmann on Friday, December 02, 2005 11:42 AM
Permalink | Comments (1) | Post RSSRSS comment feed

About the author

I'm Chris Pietschmann, go to the About Me page to learn more about me.

Search

Sponsors

Web.Maps.VE - ASP.NET AJAX Virtual Earth Mapping Server Control

Recent comments

Disclaimer


This work is licensed under a Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the posted content.
© Copyright 2004 - 2008 Chris Pietschmann