Click here to Skip to main content
6,818,958 members and growing! (20,781 online)
Email Password   helpLost your password?

Michael Freidgeim - Professional Profile


Friendly Url http://www.codeproject.com/Members/Michael-Freidgeim
Status Silver. Member No. 592585     
Questions & Answers
Messages Posted 87 - Poster
Articles / Tech Blogs
Tips/Tricks Posted
Biography None provided
Location Australia Australia
Job Title Software Developer (Senior)
Company
Member since Friday, September 19, 2003
(6 years, 4 months)
Homepage http://geekswithblogs.net/mnf/
The Reputation graph is a beta-only release. Read the FAQ for more information.

Membership status calculated as follows:

1-4 articles posted = Bronze. 5-14 articles = Silver. 15-24 articles = Gold. 25+ articles = Platinum. Each 500 messages posted adds one level, and if a member has posted a message then each year of membership adds 1 level until the member hits Silver. Bronze is awarded at the beginning of the first 500 messages posted instead of the end.
You must Sign In to use this message board.
FAQ FAQ 
 
 Msgs 1 to 7 of 7 (Total in Forum: 7) (Refresh)FirstPrevNext
GeneralMy blog at geekswithblogs Pin
Wednesday, October 5, 2005 7:26 PM
My current blog is located at http://geekswithblogs.net/mnf/[^]

Michael Freidgeim.
Blog: http://geekswithblogs.net/mnf/
 
GeneralContains method for DataReader Pin
Sunday, March 6, 2005 7:53 PM
I found that function Contains to check if field name exist in the record, is available for DataRow is missing for DataReader/IDataRecord.
So the following simple function can be useful.
public static bool Contains(IDataRecord row, string FieldName)
{
bool bRet=true;
try
{
row.GetOrdinal(FieldName);
}
catch //(Exception exc)
{
bRet=false;
}
return bRet;
}


Michael
 
GeneralChange case to string array Pin
Thursday, January 13, 2005 3:13 PM
I found that some functions with array of strings that may be useful, but they are not in framework classes.
If someone needs all strings in string array to be in low case, the following simple function can be useful.
public static string[] ToLower(string[] sArray)
{
for(int i=0;i<sArray.Length;i++)
{
sArray[i]=sArray[i].ToLower();
}
return sArray;
}


Michael
 
GeneralSmartNavigation and 'onload' JavaScript Pin
Monday, December 6, 2004 3:29 PM
I like to use SmartNavigation="true" option, but there are several problems with it.
Recently I put MetaBuilders.ComboBox[^] on the page with SmartNavigation="true" and found that after Postback ComboBox is shown as 2 different controls- text and dropdown list.
Reading source I found that rendered page has the following javascript for IE
window.attachEvent("onload", ComboBox_Init);
But the problem is that when SmartNavigation="true", postbacks do not cause onload events.
Thanks to ideas from Jim Fisher[^] and Fons Sonnemans [^] I've changed the code to the following
if(window.__smartNav!=null) //handle smartnavigation
{ window.setTimeout(ComboBox_Init,20);
}
else
{ window.attachEvent("onload", ComboBox_Init);
}

and now the ComboBox works correctly with SmartNavigation.

Michael
 
GeneralSending ASP.NET page rendered content from another ASP.NET page. Pin
Thursday, September 23, 2004 8:30 PM
My ASP.NET application used to send content of one page from another using HttpWebRequest similar to the following
        Dim objResponse As HttpWebResponse
Dim objRequest As HttpWebRequest = System.Net.HttpWebRequest.Create(url)
objResponse = objRequest.GetResponse()


It worked fine, before I desided to use session object in the sending page.
I've created CookieContainer and passed sessionID, but it didn't work.
GetResponse waited for a while and returned time-out.
As I understand, ASP.Net serializes access to session and blocks re-entrance (fair enough) .

Fortunately, I found Eric Woodruff's article[^], that gave me the solution. Thanks again, Eric.

Michael
 
GeneralStore JavaScript as embedded resource. Pin
Sunday, September 19, 2004 4:06 PM
I've seen many places where people use inline concatenation to create some JavaScript in ASP.NET VB
using String '&' operator or StringBuilder.Append.
The code is usually hard to read.
It's easier to save JavaScript fucntion code into a separate file with "build Action"="embedded resource" and use several reusable helper functions.

    Public Shared Function StreamToString(ByVal strm As Stream) As String
If strm.CanSeek Then strm.Seek(0, SeekOrigin.Begin)
Dim myReader As New StreamReader(strm)
Dim sRet As String = myReader.ReadToEnd()
Return sRet
End Function
Public Shared Function ResourceToString(ByVal ResName As String) As String
' Get the current assembly.
Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly()
Return ResourceToString(ResName, Asm) 'call overload
End Function
Public Shared Function ResourceToString(ByVal ResName As String, ByVal Asm As [Assembly]) As String
' Resources are named using a fully qualified name.
Dim sName As String = Asm.GetName().Name + "." + ResName
Dim strm As Stream = Asm.GetManifestResourceStream(sName)
' Read the contents of the embedded file.
If strm Is Nothing Then
Throw New ApplicationException("Couldn't find embedded resource " & sName)
End If
Dim sRet As String = StreamToString(strm)
Return sRet
End Function
Public Shared Function JScript(ByVal sScript As String)
Return "<script language="'javascript'">" & sScript & "<" & Chr(47) & "script>"
End Function

Or even better use Eric Woodruff's Resource Server Handler Class
[^]

Michael
 
GeneralDefault button in ASP.NET form. Pin
Wednesday, September 15, 2004 7:09 PM
I am using my own functions to set Default Button on ASP.NET web form.
They were created based on Janus Kamp Hansen sample[^] and later using Darrell Norton's code [^].
I found that it's convinient to set the same Default Button to the container that will apply for all children- container can be WebControl or HtmlControl.
And recently I found that this approach required escaping for TextArea(otherwise Enter Key submits default button instead of entering new line in text box).

'overloaded methods for WebControl and HtmlControl are required because common parent class Control doesn't have Attributes property
Public Shared Sub DefaultButton(ByVal container As System.Web.UI.HtmlControls.HtmlControl, ByVal objDefaultButton As Control)
container.Attributes.Add("onkeydown", "DefaultButton('" & objDefaultButton.ClientID & "',event);")
container.Page.RegisterStartupScript("ForceDefaultToScript", DefaultButtonScript())
End Sub
Public Shared Sub DefaultButton(ByVal container As System.Web.UI.WebControls.WebControl, ByVal objDefaultButton As Control)
container.Attributes.Add("onkeydown", "DefaultButton('" & objDefaultButton.ClientID & "',event);")
container.Page.RegisterStartupScript("ForceDefaultToScript", DefaultButtonScript())
End Sub
'call if container has defaultButton but child (eg textarea) doesn't need it.
Public Shared Sub EscapeDefaultButton(ByRef ctrl As System.Web.UI.WebControls.WebControl)
'See also DefaultButton
ctrl.Attributes.Add("onkeydown", "NoDefaultButton(event);")
ctrl.Page.RegisterStartupScript("ForceDefaultToScript", DefaultButtonScript())
End Sub
Private Shared Function DefaultButtonScript()
'
From http://dotnetjunkies.com/WebLog/darrell.norton/archive/2004/03/03/8374.aspx.
Return JScript(ResourceToString("DefaultButton.js"))
End Function

In this code I am using helper functions JScript and ResourceToString [^] to access embedded resources

JS function is stored in a separate file DefaultButton.js with "build Action"="embedded resource"

<!--
//Not sure that event.returnValue is applicable for Netscape
function DefaultButton(btnID, event){
btn = findObj(btnID);
if (document.all){
if (event.keyCode == 13){
event.returnValue=false;
event.cancelBubble = true;
btn.click();
}
}
else if (document.getElementById){
if (event.which == 13){
event.returnValue=false;
event.cancelBubble = true;
btn.click();
btn.focus();
}
}
else if(document.layers){
if(event.which == 13){
event.returnValue=false;
event.cancelBubble = true;
btn.focus();
btn.click();
}
}
}
//call if container has defaultButton but child (eg textarea) doesn't need it.
//Sets cancelBubble=TRUE, not tested for Netscape
function NoDefaultButton(event){
if (document.all){
if (event.keyCode == 13){
event.cancelBubble = true;
}
}
else if (document.getElementById){
if (event.which == 13){
event.cancelBubble = true;
}
}
else if(document.layers){
if(event.which == 13){
event.cancelBubble = true;
}
}
}
function findObj(n, d) {
var p,i,x;
if(!d)
d=document;
if((p=n.indexOf("?"))>0 && parent.frames.length) {
d=parent.frames[n.substring(p+1)].document;
n=n.substring(0,p);
}
if(!(x=d[n])&&d.all)
x=d.all[n];
for (i=0;!x&&i x=d.forms[i][n];
for(i=0;!x&&d.layers&&i x=findObj(n,d.layers[i].document);
if(!x && d.getElementById)
x=d.getElementById(n);
return x;
}
// -->


Michael

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Last Updated 8 Feb 2010
Web17 | 2.2.0226 | Advertise | Privacy
Copyright © CodeProject, 1999-2010
All Rights Reserved. Terms of Use