Very nice and flexible file upload control with progress

by filip 17. October 2008 22:03

I needed a pretty quick way of displaying file upload progress in a ASP.NET project. In the past while working for a different employer, I've written my own code from scratch, and it was a complete pain in the ass.  Fortunately, after doing a bit of searching, I've ran across an open source control that works great.  The control is called NeatUpload and can be found at this URL:

http://www.brettle.com/neatupload

Tags:

Web Development

Server Side Includes (SSI) adding a blank/empty line to HTML page

by filip 28. August 2008 14:28

While creating a page that used server side includes, I ran into some very strange behavior.  Right before each SSI, a blank line would appear on the page.  It didn't have anything to do with margins or padding.  It was just like an empty line appeared right out of nowhere, messing up the layout.  First, I thought it was some problem with IIS and SSI, but I couldn't find anything there.

After a few hours of frustration and trying the weirdest solutions I could think of, I started playing around with saving the include files with different file names. Well, when I got to the *.txt, I noticed that Visual Studio gives me a new option under "Save As"... its "Advanced Save Options". When I looked at the encoding of the file, it was set to "Unicode (UTF-8 with signature) - Codepage 65000".  I then switched to "Unicode (UTF-8 without signature) - Codepage 65001", and the blank lines disappeared. 

It appears that Visual Studio picks an encoding when saving pages that doesn't really produce desirable effects when using server side includes.  However, you can go to File -> Advanced Save Options and select a different encoding.  I'm not sure how to set the one w/o signature as the default yet, but hopefully soon I'll figure that out :)

Tags: ,

Web Development

Using LoadVars sendAndLoad instead of WebService when calling web services with Flash ActionScript

by filip 14. August 2008 14:53

I've ran into issues using the WebService object in Flash.  The thing is incredibly buggy.  In certain cases, it works just fine, but in other cases, it flat out does not work. In my last case, the web service loaded perfectly fine (onLoad was called), but the PendingCall would not return anything.  The onFault method was never called after I invoked my web service call, but the web service never returned either.  Examining the outgoing messages from Flash (using HTTP headers in Firefox) revealed that Flash was never even attempting to call the web service.  Flash did correctly acquire the crossdomain.xml file (which allowed access from all domains), and it did load the WSDL.  But, for whatever reason, it did not call the web method like it was supposed to.

Well, after a few hours or attempging to make this work, I gave up with the WebService object.  Instead, I went to the LoadVars object, something I'm more confident in than the WebService class, simply due to the fact that it has been around much longer and has had more attention from the Adobe / Macromedia team.

Using the WebService object, my code looked like the following:

var _wsdl:String = "http://www.bloodforge.com/webservice.asmx?WSDL"; // <- this is fake for the purpose of this blog 
var MailService:WebService = new WebService(_wsdl);
MailService.onLoad = function()
{
  var MailServiceResult:PendingCall = MailService.MyMethod("my parameters");
  MailServiceResult.onFault = function(fault)
  {
    trace("it never gets here even though it fails!");
  }
  MailServiceResult.onResult = function(result)
  {
    trace("it never got here either!");
  }
}

The above was replaced with the code below, and it works perfectly fine:

var result_lv:LoadVars = new LoadVars();
result_lv.onData = function(responseStr:String)
{
  if(responseStr == undefined)
  {
    trace("Error occurred!");
  }
  else
  {
    trace("Success... parse my data below...");
  }
}
var send_lv:LoadVars = new LoadVars();
send_lv.myWebServiceParam1 = "param 1";
send_lv.myWebServiceParam2 = "param 2";
send_lv.sendAndLoad("http://www.bloodforge.com/webservice.asmx/MyMethod", result_lv, "POST");

 
Oh, and make sure that if you do this with your web service, that you have the following line in your web.config file.  Otherwise, you won't be able to access it using these methods (you should be familiar w/ it anyways if you use Ajax to call web services).

<webServices>
  <
protocols
>
    <
add name="HttpGet"
/>
    <
add name="HttpPost"
/>
  </
protocols
>
</
webServices>

Tags: , ,

Web Development

IE8 and AjaxControlToolkit - Visibility bug

by filip 18. June 2008 14:08

Well, I finally downloaded IE8 to see how some of the sites I've worked on behave.  Most things work just fine, however, I did find a pretty significant problem with the AjaxControlToolkit.

I've been using the Tab control quite a bit, and I noticed that, when switching between tabs, the new tab was not showing up.  The old tab was hiding, though... 

Debugging has led me to the setVisible method located in "Common/Common.js" in the AjaxControlToolkit.  Specifically, the problem existed in the following code:

if (element && value != $common.getVisible(element))
{
  if (value) 
  {
    if (element.style.removeAttribute)
    {
      element.style.removeAttribute("display"
);
    }
    else

   
{
     
element.style.removeProperty(
"display"
);
   
}
 
}
 
else
 
{
    
element.style.display
= 'none'
;
 
}
 
element.style.visibility
= value ? 'visible' : 'hidden';
}

In the above code, removeAttribute() was being called, but the display attribute remained (display=none).  I looked up the removeAttribute method, and it does return a boolean value indicating if the method was successful or not.  Well, as it turns out, the method (for whatever reason) is not successul in IE8!

I'm not sure why this fails in IE8, but it does cause a problem.  Fortunately, there's a pretty quick fix to this:

if (element && value != $common.getVisible(element))
{
  if
(value) 
  {
    if
(element.style.removeAttribute)
    {
            if(!element.style.removeAttribute("display"))
            {
               element.style.display
= ''
;
            }

    }
   
else
   
{
     
element.style.removeProperty(
"display"
);
   
}
 
}
 
else
 
{
    
element.style.display
= 'none'
;
 
}
 
element.style.visibility
= value ? 'visible' : 'hidden';
}

Tags: , ,

Web Development

Using JavaScript methods in C#

by filip 4. June 2008 14:09

I ran into a weird problem today.  I needed to escape a string in c# in such a way as to be able to unescape() it later with JavaScript into the original string.  JavaScript has an escape() method that is able to do this, but since I'm writing the code in C#, I can't really access that method.  At first, I looked into HttpServerUtility.UrlEncode() and the HttpServerUtility.HtmlEncode() methods, but those are not equivalent to JavaScript's escape() method. 

However, it seems Microsoft has put in a library which gives us access to JavaScript methods ( whether this is simply mimicking what JavaScript does or if it actually uses JavaScript... I could really care less).  All that was needed is a reference to Microsoft.JScript in the project, and I was able to call the Microsoft.JScript.GlobalObject.escape() method, and it produces the exact same output as the JavaScript version.

Tags: ,

Web Development

Bloodforge Band

Looking for the Bloodforge band site? Click here.

About Filip Stanek

Death Note Pic I'm a developer at ACG in Cincinnati, OH. I like ASP.NET, Flash, and other web technologies, & enjoy playing chess, video games, etc.

Currently playing:

Disqus

Month List