| 5/29/2008 9:59 PM: | | Position changed...
My career has taken a turn this year...and I thought I would post a note as to why there has been such a lack of information on the c#/ development topics for quite some time.
I love programming- it is something that I both enjoy and find relaxing (only a programmer can relate to that). I feel that I had to address my future with regards to my family and started the process of moving into management late last year- I am sorry for the betrayal to ALL programmers- my heart is really there!!! 
I will still be programming for a hobby and want to further my knowledge in the smartphone/ professional phone software development arena with the introduction of VS 2008 etc.. I have already put some software (free) on the downloads section of the web site but hope to increase my offerings over time.
As I find the "features" that Microsoft put into their software, I will endeavor to put them in this blog (as well as those pointed out by my peers), but I expect this section of my blogs will become a little redundant over time...
Once again, I am sorry!!! 
|
|
| 8/15/2007 8:23 AM: | | Client JavaScript and .NET Server Controls
The new .NET model renames the server controls dynamically, giving them a unique ID. See below for an example.
The following is the control on the ASPX page designer:
<asp:CheckBox id=chkBInfo runat=server checked=true/>
This is rendered to the client in HTML as:
<input id="ctl00_ContentPlaceHolder1_chkBInfo" type="checkbox" name="ctl00$ContentPlaceHolder1$chkBInfo" checked="checked" />
As you can see, the controls name cannot be determined easily...or can it???
Well, so long as your JavaScript remains on the same ASPX page, you can get the control using "ClientID":
function theForm_onSubmit(){
if (document.forms(0).<%=chkBInfo.ClientID%>.checked==false)
{
alert('Please select a Message Type...');
return false;
}
}
Hope this helps!!! 
|
|
| 8/14/2007 11:16 AM: | | Add a CSS header dynamically...
With the increased use of Master pages etc, I had the need to add the CSS stylesheet dynamically depending on the situation.
Putting the following code in the Page_Load event of the individual page solved the problem:
// add the stylesheet..
HtmlHead myHeader = (HtmlHead)this.Page.Header;
if (theHeader != null)
{
HtmlLink myCSS = new HtmlLink();
myCSS.Attributes.Add("href", "admin/td_codes.css");
myCSS.Attributes.Add("rel", "stylesheet");
myCSS.Attributes.Add("type", "text/css");
theHeader.Controls.Add(myCSS);
}
|
|
| 12/15/2006 8:20 AM: | | ASP.NET Error: No connection could be made because the target machine actively refused it
The answer for us was...USE A PROXY!!! 
Uri myuri = new Uri("http://" + System.Web.HttpContext.Current.Request.ServerVariables.Get("HTTP_HOST") + "/" + Request.QueryString["source"].ToString());
WebRequest myRequest = System.Net.HttpWebRequest.Create(myuri);
System.Net.IWebProxy proxyObject = new System.Net.WebProxy("http://dummy:80", true);
myRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
myRequest.Proxy = proxyObject;
Stream result = myRequest.GetResponse().GetResponseStream();
navDocument.Load(result);
|
|
| 10/26/2006 4:53 PM: | | I closed the forum so the code is here...
For security reasons, I have closed the GibbsUSA.net forum...so I am using this blog to post my own comments and observations related to C#...
|
|
| 10/26/2006 4:49 PM: | | ASP.NET Debug Error 0×8013134b
I recently had the following error when trying to debug (locally) an ASP.NET C# project given to me by a contractor...
Auto-attach to process "[2440] w3wp.exe" on machine "SERVER1" failed. Error code 0×8013134b.
The problem turned out to be that I had installed .NET 2.0 which had registered ASP.NET 2.0 on the web site I was trying to debug !
The solution was:
- Run IIS
- Select the site with the issues, right click and select Properties then click on the ASP tab
- Change the ASP.NET version from 2.x to 1.x
|
|
| 10/26/2006 4:47 PM: | | Remove HTML tags using Regular Expressions
Recently I needed to remove specific HTML tags from a string obtained from a database. The use of Regular Expressions made this a single line of code using the Replace functionality:
string output = Regex.Replace(input, @"</?(?i:meta|embed|script|frameset|frame|iframe|object|link)(.|\n)*?>", "");
This code removes the following HTML tags:
meta
embed
script
frameset
frame
iframe
object
link
As you can see, this is easily changed to reflect any tags that you may want removing!
God I love those Regular Expressions!!!
|
|
| 10/26/2006 4:34 PM: | | Making URLs search engine friendly
Here is an example of turning a querystring into a search engine friendly URL..
The URL comes from a search engine in the format:
www.gibbsusa.net/develop/rss/blogs/showblog_page-ID-8.aspx
The code converts this transparently to the following URL:
www.gibbsusa.net/develop/rss/blogs/showblog.aspx?ID=8
The following snippet comes from the global.asax file
protected void Application_BeginRequest(Object sender, EventArgs e)
{
// code to make blogs search engine friendly
HttpContext incoming = HttpContext.Current;
string oldpath = incoming.Request.Path.ToLower();
if(oldpath.ToLower().IndexOf("_page-")>0)
{
string pageRedirect = oldpath.Substring(oldpath.LastIndexOf("/")+1);
pageRedirect = pageRedirect.Substring(0,pageRedirect.ToLower().IndexOf("_page"));
// extract the items
string qsItemsTemp = oldpath.Substring(oldpath.ToLower().IndexOf("_page-")+6);
qsItemsTemp = qsItemsTemp.Substring(0,qsItemsTemp.ToLower().IndexOf(".aspx"));
string[] qsItems = qsItemsTemp.Split('-');
string theQString = "";
for (int i=0;i<=qsItems.GetUpperBound(0);i++)
{
if (theQString.Length>0)
{
theQString += "&";
}
theQString += qsItems[i].ToString() + "=" + qsItems[i+1].ToString();
i++;
}
incoming.RewritePath (pageRedirect + ".aspx?" + theQString);
}
else
{
// Display path if it doesn’t contain _pageX.aspx
incoming.RewritePath(oldpath );
}
}
|
|
| 10/26/2006 4:28 PM: | | Trapping dangerous client input (eg. cross site script HTML)
With the 1.1 framework, Microsoft introduced the HttpRequestValidationException Class (see HttpRequestValidationException Class).
This exception is thrown when a potentially dangerous input string is received from the client.
To use this class, simply override the System.Web.UI.Page OnError event. For example, add the following code to your page...
protected override void OnError(EventArgs e)
{
System.Exception theError = Server.GetLastError();
if(theError.GetBaseException() is System.Web.HttpRequestValidationException )
{
System.Diagnostics.Debug.Assert(false);
Response.Write("<hr><p align=center>BAD BOY!!! You are trying to insert HTML tags or XSS script to the field.<br>Please use the button below to remove the tags from your input!<br><br>Thank you...</p>");
Response.Write("<p align=center><input type=button language=javascript value='<< BACK' onclick ='window.history.go(-1);'></p><hr>");
Response.StatusCode = 200;
Response.End();
}
}
|
|