Life, Surf, Code and everything in between
White Papers | Free Tools | Products | Message Board | News |

Last 24 Comments

re: ASP.NET 2.0 MasterPages and FindControl()
Today @ 3:24 am | by Alex

Thanks for the post AND many thanks to ScottGu for the tip about the "CodeFileBaseClass" @ page attribute, had no idea about it.
re: .Net Reflection and Performance
Today @ 3:00 am | by Charles Cai

So I added more tests, i.e. cached reflection (we cached PropertyInfo and MethodInfo), 2 more .NET 4.0 PLINQ enabled version, one for normal, one for reflection, and the results on a dual-core PC are:

Normal test used: 1500ms
NormalPlinq test used: 786ms

Reflect test used: 2923ms

ReflectCache test used: 2576ms
ReflectCachePlinq test used: 1353ms


You can see on a dual-core PC, PLINQ doubles the performance and bring our cached reflection code FASTER than normal call; on the other hand PLINQ double the normal call performance too :)

Any other way to optimize our reflection code?
Any ways to avoid boxing/unboxing if we are dealing with value types?


Console c# source code running on VS2010 RC:

using System;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
 
namespace ConsoleApplication1
{
    class Program
    {
        private String Output { get; set; }
 
        static void Main(string[] args)
        {
            var p = new Program();
            var stopwatch = new Stopwatch();
            
            stopwatch.Start();
            p.TestNormal(stopwatch);
 
            stopwatch.Restart();
            p.TestNormalPlinq(stopwatch);
 
            stopwatch.Restart();
            p.TestReflection(stopwatch);
 
            stopwatch.Restart();
            p.TestReflectionCached(stopwatch);
 
            stopwatch.Restart();
            p.TestReflectionCachedPlinq(stopwatch);
        }
 
        string ReturnDate()
        {
            return DateTime.Now.ToString();
        }
 
        void TestNormal(Stopwatch stopwatch)
        {
            this.Output = DateTime.Now.ToString();
 
            for (int x = 0; x < 200000; x++)
            {
 
                // *** Get Property Test - note we have to set the value here or else the compiler will optimize the assignment
                this.Output = DateTime.Now.ToString();
 
                var Value = this.Output;
 
                // *** Set Property Test
                this.Output = DateTime.Now.ToString();
 
                this.Output = this.ReturnDate();
            }
 
            Debug.WriteLine("Normal test used: " + stopwatch.ElapsedMilliseconds + "ms");
        }
 
        void TestNormalPlinq(Stopwatch stopwatch)
        {
            this.Output = DateTime.Now.ToString();
 
            Parallel.For(0,
                         200000,
                         (i) =>
                             {
 
                                 // *** Get Property Test - note we have to set the value here or else the compiler will optimize the assignment
                                 this.Output = DateTime.Now.ToString();
 
                                 var Value = this.Output;
 
                                 // *** Set Property Test
                                 this.Output = DateTime.Now.ToString();
 
                                 this.Output = this.ReturnDate();
                             });
 
            Debug.WriteLine("NormalPlinq test used: " + stopwatch.ElapsedMilliseconds + "ms");
        }
 
        void TestReflection(Stopwatch stopwatch)
        {
            for (int x = 0; x < 200000; x++)
            {
                this.Output = DateTime.Now.ToString();
                string Value = (string) this.GetType().GetProperty("Output", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this, null);
                    //,BindingFlags.Instance | BindingFlags.NonPublic,null,null);
 
                // *** Set Property Test
                this.GetType().GetProperty("Output", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, DateTime.Now.ToString(), null);
                    //,BindingFlags.Instance | BindingFlags.NonPublic,null,null);
                string value = (string) this.GetType().GetMethod("ReturnDate", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(this, null);
            }
            
            Debug.WriteLine("Reflect test used: " + stopwatch.ElapsedMilliseconds + "ms");
        }
 
        void TestReflectionCached(Stopwatch stopwatch)
        {
            var pi = this.GetType().GetProperty("Output", BindingFlags.Instance | BindingFlags.NonPublic);
            var mi = this.GetType().GetMethod("ReturnDate", BindingFlags.Instance | BindingFlags.NonPublic);
 
            Func<string> getter = () => (string) pi.GetValue(this, null);
            Action<string> setter = (s) => pi.SetValue(this, s, null);
            Func<string> getMethod = () => (string) mi.Invoke(this, null);
 
            for (int x = 0; x < 200000; x++)
            {
                this.Output = DateTime.Now.ToString();
                string Value = getter();
 
                setter(DateTime.Now.ToString());
 
                string value = getMethod();
            }
 
            Debug.WriteLine("ReflectCache test used: " + stopwatch.ElapsedMilliseconds + "ms");
        }
 
        void TestReflectionCachedPlinq(Stopwatch stopwatch)
        {
            var pi = this.GetType().GetProperty("Output", BindingFlags.Instance | BindingFlags.NonPublic);
            var mi = this.GetType().GetMethod("ReturnDate", BindingFlags.Instance | BindingFlags.NonPublic);
 
            Func<string> getter = () => (string)pi.GetValue(this, null);
            Action<string> setter = (s) => pi.SetValue(this, s, null);
            Func<string> getMethod = () => (string)mi.Invoke(this, null);
 
            Parallel.For(0, 200000,
                         (i) =>
                             {
                                 this.Output = DateTime.Now.ToString();
                                 string Value = getter();
 
                                 setter(DateTime.Now.ToString());
 
                                 string value = getMethod();
                             });
 
            Debug.WriteLine("ReflectCachePlinq test used: " + stopwatch.ElapsedMilliseconds + "ms");
        }
    }
}

re: jQuery Books Review
Today @ 1:43 am | by Inner Game

Are you able to update the links for the cheat sheets? I'd really like to get me hand on them.


Leigh
re: Client Templating with jQuery
Yesterday @ 7:08 pm | by jhs

Here is a new jquery template plugin "YATE" that separates the template markup from the javascript data and logic pretty nicely: http://labs.mudynamics.com/2010/03/19/yate-javascript-templating-engine-for-agile-ui-development/
re: Calling JavaScript functions in the Web Browser Control
Yesterday @ 1:39 pm | by mishi

Hi Rick,
Thanks for the post. I'm facing an issue with getting the document object from the web browser control. This works if the document I navigate to is on the disk (local or UNC path). However if I have this hosted in IIS and provide the url as http://localhost/mytest.htm I cannot get the document object. I am launching this from an activeX control that is embeded within an aspx page.

I am using C++ (since our legacy activeX is in C++) and the code is something like:
COleVariant* pvarURL = new COleVariant( _plugInDetails.pluginURL.c_str() );
COleVariant* pvarEmpty = new COleVariant;
_browser.Navigate2( pvarURL, pvarEmpty, pvarEmpty, pvarEmpty, pvarEmpty );
delete pvarURL;
delete pvarEmpty;

LPDISPATCH spDisp = _browser.GetDocument();
//this line immediately returns NULL - if this url is of the form http://xyz. If the url is on disk all goes well.


Any ideas? Btw the activeX control is marked safe for scripting and initializing.

Thanks
re: I can’t find my Find Dialog in Visual Studio
Yesterday @ 10:48 am | by Paul Brown

I know this post is stale but it just happened to me. In VS2010, you can use Window -> Dock to dock the window. ALT-M didn't work because it was mapped as a menu shortcut.
re: Sql 2008 Management Tools: Can't save changes that require Recreation of Database
Yesterday @ 6:28 am | by Nate

I got this and deleted my table to make the changes. When I went to save the new table with the same name it said the table can not be created because it exists???
Searched sysobjects and it does not exist - But I can not create the table again.

Can anyone point me in the right direction?

Thanks!!
re: Installing Windows with Additional Drivers and no Floppy drive?
Yesterday @ 5:08 am | by Keith

THANK YOU ANDREAS!!!!! Disabling AHCI in the bios saved me from going insane.

I was struggling with reinstalling Win XP Pro on an HP xw4300 with a SATA HD and no floppy. After hours of searching I came across this post from a Google search.

I am a 20 year devoted Mac tech that is forced to do windows from time to time. It's amazing that after all these years, building or fixing a PC still requires a floppy drive and a working slave computer to complete the task.
re: Monitoring HTTP Output with Fiddler in .NET HTTP Clients and WCF Proxies
Thursday @ 9:55 pm | by Adam Coyne

I found this page while trying to use Fiddler to monitor client requests made by an ASP.NET application. Adding proxyaddress="http://127.0.0.1:8888" in web.config as you suggest above works, but it means that I have to edit web.config when I close Fiddler, or all client requests will fail since the proxy is gone.

Another (tricky) way of doing this is to specify usesystemdefault="True", and run Fiddler as SYSTEM using Sysinternals psexec: psexec.exe -i -d -s "C:\Program Files\Fiddler2\Fiddler.exe"

That enables me to see the requests and have them still work when I close Fiddler.
re: Visual Studio 2005 IntelliSense in ASP.NET pages issue resolved...
Thursday @ 2:10 pm | by Drew

I have been chasing this problem for 2 weeks, and now I decided to fix it today. I have posted this comment on 2 other blogs, but no one has answered yet.

I get no joy when trying any of the above. I have altered the /html line, changed the spacing around the @Page declaration, and changed the Tools, Options, Text Editor, All Languages, Hide advanced members checkbox. None of the above work.

I don't get any intellisense in the .ASPX file snippet shown below:

<%@ Page Language="VB" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" type="text/VB" language="vbscript">
   Dim sSubPageName as string, sSectionName as string, sLinkName as string
   dim s as 
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      If IsPostBack Then
         '
         statusMessage.Text &= "hi"
      end if
      statusMessage.Text &= sSectionName
   end sub
       
</script>
<html> ... </html>

re: .NET WebRequest.PreAuthenticate – not quite what it sounds like
Thursday @ 12:02 pm | by JW

So glad I found this. I have this issue calling a JAX-WS on a weblogic server, not exactlly odd ball in my mind so am I doing something wrong on the ejb side?
re: altering ASP output
Thursday @ 11:46 am | by victor

The method used in this great article works well with non ASP pages, but I need to modify the output of pages created with ancient ASP code.

I have found that if I request a file with a .asp extension, and if I alter the Response.Filter in any way in any module at any point in the IIS pipeline - I am greeted with the error "This type of page is not served". Indicating perhaps that the .Net runtime is being told to process an ASP page?

Any suggestions (besides create an isapi filter)?
re: ASP.NET Designer Control Problem in VS 2008 SP1
Thursday @ 10:29 am | by Chuck

Sorry, I accidentially hit return and may have uploaded a partial comment earlier. To finish my previous rant, er.. comment... the DropDownList will show up in debug mode on the Locals window under the tree item "this". However, is you try to reference it in code behind, you will get the error message: "Named control nnnnnn does not exist in the current context"!

MS hasnt owned up to this one yet as far as I can find.

Oh, and no matter how many successful builds I did, the error always came back. I tried building with the control in the markup and without references in the code behind, deleting it all and rebuilding, all kinds of scenario's ad nauseum.

So that just leads you to a workaround which is to use FindControl to get a reference to it and cast it to a local protected variable of that same type. However, you must use the id name found in the control tree and not the ID you used in the markup. Keep in mind that DropDownList1 becomes ctl00$Main$DropDownList1 at runtime. (or something like it depending upon master pages, etc....)

To get the runtime ID, set the markup directive Trace="true" to get the control tree output at the bottom of the page in question. Copy and paste the id into the FindControl argument and you have it. The trace output will look something like this:

ctl00$Main$ctl02 System.Web.UI.ResourceBasedLiteralControl 323 0 0
ctl00$Main$DropDownList1 System.Web.UI.WebControls.DropDownList 436 216 0
ctl00$Main$ctl03 System.Web.UI.LiteralControl 152 0 0
ctl00$Main$lblcourtHouseName System.Web.UI.WebControls.Label 188 0


Depending upon your comfort level with which control it is going to find, you may want to do a little checking on it first before using the casted control, so check the type and do you due-diligence.

Here's the code:

public partial class Default_aspx  : System.Web.UI.Page
{
 
    protected DropDownList myDropDownListFix;
 
 
    protected void Page_Load( object sender, EventArgs e )
    {
        //  get a reference to the desired control
        Control myControl = FindControl("ctl00$Main$DropDownList1");
 
        //  make sure you have the right type       
        if (myControl.GetType() == typeof(System.Web.UI.WebControls.DropDownList))
        {
            // now safe to cast it to the one you want and work with it
            myDropDownListFix = (DropDownList)FindControl("ctl00$Main$DropDownList1");
            myDropDownListFix.Items.Add("Me");
            myDropDownListFix.Items.Add("You");
            myDropDownListFix.Items.Add("Calib");
            myDropDownListFix.Items.Add("The Horses");
        }
.
.
.
.


I'm sure there are more elegant ways to do this, but it is a *workaround*.
BTW, after I did the manual fix, it all started working again. So, I'm not sure whether to take the workaround out or not. Not real dependable there MS.....VS200x gotta love it. Definitely a love-hate relationship.

I know this doesnt address any event handler problems you may have when you dont have visibility to the control. If I wind up in visibilty purgatory again, I will post the fix here, friends.
But for now it started working. Not LOL.
Cheers.
re: Setting ACE/ACL permissions in .NET 2.0
Thursday @ 6:14 am | by Steve Walton

Thanks Rick.

Great article. Solved my problems when the MSDN documentation was not helping at all.

Thanks again.
re: Retrieving Browser Scroll Position in JavaScript
Thursday @ 5:25 am | by dima

thanks, there is shorter code:)

    
var top = document.body.scrollTop
          || window.pageYOffset 
          || (document.body.parentElement
              ? document.body.parentElement.scrollTop
              : 0
              );

re: Packaging ASP.NET ASPX Pages into a separate Assembly
Thursday @ 2:12 am | by Psy After

It's nice tutorial, but I've exception when executing end point Page (in example is SubProject.DefaultASPX_PAGE).
The error is "Object reference not set.." when I try to use any user control on page in code behind.
In my page I've literal control that I want init (in Page_Init) with text in code behind.
On those row the I receive a run time error.

Whant can be a problem?
Any help will be appreciated, thank you in advance.
re: Updated jQuery Calendar to jQuery DatePicker
Wednesday @ 7:50 pm | by Truong Le Khanh

If i set Enabled=true
<ww:jQueryDatePicker ID="jQueryDatePicker1"   Enabled=true runat="server"  ></ww:jQueryDatePicker>

The error show at "inst._input[0].focus();":
_updateDatepicker: function(inst) {
        inst._datepickerDiv.empty().append(inst._generateDatepicker());
        if (inst._get('numberOfMonths') != 1) {
            inst._datepickerDiv.addClass('datepicker_multi');
        } 
        else {
            inst._datepickerDiv.removeClass('datepicker_multi');
        }
        if (inst._input && inst._input[0].type != 'hidden') {
            inst._input[0].focus();
        }


Info: htmlfile: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.
re: Creating a data driven ASP.NET Resource Provider and Editor Article posted
Wednesday @ 4:08 pm | by Camilo

Hi Rick I am having a problem with the Recycle App button, it doesn't look like it recycles the app correctly since I don't see the changes in the site after that button is clicked, I have to go to IIS and restart the app in order to see the changes.

Any help would greatly be appreciated and thanks a lot

Camilo
re: Don't use NOVA for CC Processing
Wednesday @ 1:37 pm | by Jeremy

We are fighting with them. We have been hit with two chargebacks based on credit card fraud by the purchaser. Elavon has not only put through the chargeback but they have also held $2700 for a minimum of 270 days, because we are now supposivly a high risk. We keep trying to contact someone to get things straightened out and they either contact us to non-existing lines that hang up on you or the rep is on vacation or you get a voicemail for some person who wants to know if you are calling into work. We are out not only the money but also the product and yet even though we are paying this company they treat us like we are the criminals. They have offered no help to us in how to recover any money. They are the rudest most vague people who never have an answer and could care less about the consumer. We finally had to go to our bank and after a run around she got somewhere but who knows if that will get our money back. I want to cancel the account but after reading all of the post now I am worried about that process to. Everyone should report them to the Better Business Bureau. When I looked them up they had an A+ rating. That needs to change with the way that they are treating businnesses. I will be reporting them and as for a class action lawsuit I would take part in that.
re: A simple Business Object wrapper for LINQ to SQL
Wednesday @ 12:29 pm | by Rick Strahl

@G - Linq to SQL handles stored procedures as method imports on a static object and you can use those imports directly. The behavior of those stored procedure results are the same as returned lists or entities run with explicit LINQ statements, so there's no special handling required.
re: VB.NET rant
Wednesday @ 11:53 am | by Emmanuel Huna

VB.NET developers are about productivity: background compilation and case insensitivity are just two examples of why I love it and I can't stand working in C#.

Plus adding all of those squiggly brackets and semi-colons gets tedious fast.
re: A simple Business Object wrapper for LINQ to SQL
Wednesday @ 9:22 am | by G

Hi,
I was wondering about using stored procedures with your approach. Do you already do this or do you not bother with stored procedures in favor of using LinqToSql queries? If you do use stored procedures, can you explain your approach?
Thanks,
G
re: ASP.NET Caching under Memory Pressure
Wednesday @ 5:05 am | by William

although ASP.NET is wonderful tool of caching but it is good for small web farms only once your app started to grow then after a certain point (something like more then 2 servers), it started to give you a lot of problems most important being performance and scalable problems along with one which is discussed in this article. in my opinion the best way to overcome these issues is the use of a distributed .NET caching solution. there are some very good distributed caching solution are available which really are doing the tricks for the developers for example NCache, Velocity etc

http://www.alachisoft.com/ncache/index.html


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2010