ASP.NET Cafe
new tricks every week

Insert flash into page without "Click to activate and use this control" in IE.

Wednesday, 26 December 2007 05:43 by dmitriy

In some recent versions of Internet Explorer flash movies need a click to activate them. It is frustrating specially if your flash is a part of page design. But some solution known. In other words we need one code for IE and other for Opera, Firefox, Safari and other your favorite browsers. But asp.net custom control makes this possible.

Consider details. First of all we need to know the browser. No problems - Page.Request.Browser.Browser returns browser name. So, now we know what browser request our page. Next step, is to render correct html for IE. The main idea - to write flash <object> node from external javascript file inside some container (div in this implementation). Ok. But it's not very good to carry JavaScript file with our custom control. Yes, but we are going to embed javascript inside our dll. Here is our javascript:

function ActivateFlash(id,content)
{
    document.getElementById(id).innerHTML = content;
}

Fairly simple stuff... But we can't write it on the same page, it's important to put it in the external javascript resource. So, it's the file activate.js.

To embed it inside our assembly we need to change build action to "Embedded Resource" and add this line to AssemblyInfo.cs:

[assembly: System.Web.UI.WebResource("EmbedFlash.activate.js", "application/x-javascript")]

Also, we need to provide following properties: Width, Height, WMode (windowed, opaque, transparent) and flash file url (SWFURL).

Another interesting thing, we want to browse for the swf file in design mode. To do this we need to add following attribute to our SWFURL property:
[EditorAttribute(typeof(System.Web.UI.Design.UrlEditor), typeof(UITypeEditor))]

It tells designer to use UrlEditor class as UITypeEditor for this property.

More information you can find inside source code.

Embed Flash - Sources.zip (96.10 kb)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   ASP.NET | Flash
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

ASP.NET: 3 Steps to embed web resources into dll

Sunday, 23 December 2007 22:44 by dmitriy

If you want to make your own custom control. Yes, custom - not user control. You have something that should work good, everywhere and run from single dll. But how to store images, javascript and other stuff inside this dll? More...

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Solution for InvalidCastException error in an ASP.NET

Wednesday, 19 December 2007 06:49 by dmitriy

I write a lot about errors because it's hard to find a right solution for them over internet. Many forums with a lot of offtop... makes me mad.

So, two errors: 

Unable to cast object of type 'ASP.type' to type 'ASP.type'.

or

Could not load file or assembly 'App_Web_xxxxxxxx, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Both errors appear in ASP.NET application from time to time. There are some info about master pages, nested user controls related to this stuff. And hotfix from MS, usually. Not sure that hotifx helps, but you can try. Anyway, this error last till application automatic rebuild. So, you can just reupload/change some files of your project, and force rebuild. There are some notices that this error can occur weekly or even daily. Restart app every day is not looks good. Bad news. Avoid of master pages and user controls usage - is a bad idea. 

But immediate cause of this - incorrect automatic compiler work. So, to correct this error on production hosting, you can use precompiling.

The advantages of precompiling:

  1. You don't need to upload any source code on server. (Woo Hoo - hosting guys can't take your application)
  2. Above error not occurs, because source already compiled. (I recommend -fixednames option usage).
  3. Less delays because of recompiling.
  4. Small site size.

How to make your site precompiled (prepare for publish)?

Let's start. First of all, locate this utility C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe (your path can be different because of windows directory). After that create a cmd-file with following content:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -fixednames -p d:\projects\web1\source\ -v / d:\projects\web1\build\

Some descriptions regarding this line:
     -p  sets physical path to your web site source
     -v  sets virtual directory where you want to publish your site ( / set the root of virtual directory, 99% that you don't need to change this )
     -fixednames binaries will be given fixed names

I'm suggest that this should be used only for production hosting, because in case of frequent updates... not very comfortable to work through build.

The article on Microsoft about issues mentioned above.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

ASP.NET For Beginners: This funny <%# and <%= markup

Tuesday, 18 December 2007 01:28 by dmitriy

Everybody who starts to learn ASP.NET techniques ask the question: What is <%= and <%# What is the difference, and how to use this?

First of all, these instructions looks the same. Both outputs something in the place located. But truly output instruction is only <%= , like all Java developers already know. It allows you to output some variable or function result in the place you put it, for example <%= this.FirstName %> . This instruction is good for your user controls (ascx) that represents some view of your data.

What is the second instruction? <%# is much reacher then previous. But it can be used the same way (funny, yes). With only one restriction: it can be used only inside databindable control template. For example, Repeater, Datalist, Datagrid. Usually used to evaluate current data item values in controls template. Example of usage is: <%# Eval("FirstName") %>. That's all ? No, also there are one very powerful thing - Two-way databinding in some controls like FromView and Datagrid. So, how it works. You can put two-way databinding instruction inside some controls property. Look at the following sample: 

<asp:TextBox ID="EMailTextBox" runat="server" Text='<%# Bind("EMail") %>'></asp:TextBox>

And now FormView control not only evaluate value of EMail field, but also update in datasource with new one, if Update or Insert command comes.

This is a basic things you need to know to start using ASP.NET. Usually, this is just review.

You can find more about Two-way databinding in MSDN.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Geographic targeting in Google

Monday, 17 December 2007 02:32 by dmitriy

Every webmaster knows that Google is the king of generic traffic. And this is very important to be on good place in Google. 

Google introduced new option for webmasters: Geographic targeting... It looks like a good news, because now you can target you site to specific location. But, there are  bad news, the sites with regional domains (.uk .us .dk) targeted on these countries by Google automatically. Does that means that now if your site targeted world-wide but historically hosted in some regional domain lost visitors? Currently we have no answer about this, but I think this can affect traffic of sites that are hosted on regional domains.

Bad in this new feature of webmaster tools that you can't change geographic targeting for site located on regional domain. You'll see the following message

"Your site's domain (.XX) is already associated with the country/region: XXXXX"

This info can be interesting for owners of regional domains. You can check it in Google Webmaster Tools

I've currently mentioned that one my site on regional domain affected by this change. And I'm thinking to move it smoothly to some .com .org or .net domain to be world wide. So, don't locate your new site on regional domain, better longer, but world-wide.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Google | Google
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Again Scheduled Task in ASP.NET

Saturday, 15 December 2007 13:12 by dmitriy

Recently I've explained how to call aspx page on schedule using VB script. But now there are another problem... How long your work ?
Let me explain, ASP.NET server has default timeout... for request. It called Request Timeout. And if your request last longer... thread stopped.
Bad news. Specially, if the work is long by design. I'd a task that downloads fresh content from FTP - about 30mb. And a timeout of 110 second on server. Sometimes my request was kicked (yes, slow and bad server, I know). But what if - no money for Dedicated  where you can setup your own default timeout ?

The answer is very-very simple - this.Server.ScriptTimeout = 1800;

Put this code inside you page Load event handler - and your request timeout - 30 minutes,  not bad at all.

That's all for now.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   ASP.NET
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

CSS: min-height everythere

Thursday, 13 December 2007 20:24 by dmitriy

Recently was an article on Digg... "Don't use CSS ever" or something like this... Opened link - just another SEO company. So, I decided to write post about CSS.

Sometime you need a block elements that should be specified size, but if there are more content - grow vertically. Basically, this is a frequent trouble for peoples who works long time with IE and then see the problems in Firefox.

Here is my little css:

 _height: 458px; /* IE 6 only */
 min-height: 458px;
 display:block;

That's all. All good browsers support min-height and IE uses "height" like min-height, but just need to make it IE-only, so we are using "_height" attribute.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   CSS
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Track you visitors Geo location

Thursday, 13 December 2007 05:58 by dmitriy

Google Gadget for you site to show geographic location of visitors. Nice thing for registration pages, comments pages. You can put this Gadget on your web site.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Google | Google | Gadgets | Gadgets
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

HOWTO: Get Complete SQL dump of SQL Express 2005 Database

Wednesday, 12 December 2007 07:37 by dmitriy

The problem:

Post-PHP developers always ask me about this. Because there are good know solution for MySQL in phpMyAdmin, but not so know for MS SQL Express. Usually, we are talking about ASP.NET, and we can easily decide what DB to use. MySQL very good database too and I'm often use it for web projects. 

While developing ASP.NET projects using SQL Express 2005 Database everything is good until you need move your database on server. Usually the best to create install script, but how to dump database schema and data ? For web developers, who just started ASP.NET development... or used MSDE before this can be a big problem.

The solution: 

The first way to publish everybody tries - DTS wizard... But there are no DTS wizard in SQL Express 2005.

The second way we can find over internet - some "strange" Export/Import functions in SQL Management Studio. So, after long search how to add these functions to Management Studio - no results.

And the right way. Appears, that Microsoft created  Microsoft SQL Server Database Publishing Wizard 1.1 that solves all the problems. Neat! It works with  Visual Studio 2005 and/or Visual Web Developer 2005.

Summary: 

So, what we need to develop project for ASP.NET 2.0:

1. Visual Web Developer 2005

2. Microsoft SQL Express 2005

3. Database Publishing Wizard

4. ASP.NET 2.0 Hosting

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Main | Main | ASP.NET | ASP.NET | SQL | SQL
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed

Scheduled task in middle trust enviroment

Monday, 10 December 2007 20:19 by dmitriy

Always wondered, how to run scheduled tasks on windows hosting. For example, under the Plesk control.
At the first look, everything is ok. We have scheduled task and "command line" for it. But what to write there? This is a big question.

Somebody says - no problem, I'll write "iexplore http://example.com/track.aspx"

But I'm wondering, who closes this internet explorer process on server, and what if you are going to run this task each 5minutes?

I don't like this way. So, where is the answer? Answer inside VB. All what we need - is to create vb script and run it inside command string.
This script creates Microsoft.XMLHTTP instance (yes, we don't need to check anything like in AJAX deal, because we are certainly in Microsoft environment). And using this instance request your ASPX page to do all the job.

So, when I've asked my hosting support, how to call aspx page scheduled - they said - this impossible. Call PHP page and there request your ASPX if you want. No, thanks.

  Plesk screen... to add scheduled task. "Path to executable" should be set to ABSOLUTE path to vbs file on server. Where you can get this path... First of all, you hoster should give you info about your site's folder. If not, write a simple aspx page with Server.MapPath("my.vbs");

So, what inside VB file?


shedule.vbs (587.00 bytes)

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   Hosting | Hosting
Actions: E-mail | del.icio.us | Kick it! | DZone it! | Permalink | Comments (0) | Comment RSSRSS comment feed