Archive for March, 2007

ajax extensions file upload workaround

Posted on March 31, 2007. Filed under: Uncategorized | Tags: , , , |

In my previous post of “Upload files using asp.net ajax extensions,” I had written my approach that I implemented to upload files. As about 65% of the total clicks to my blog page is only to that post, I have decided to write a new post with complete codes for file upload. The code is fully functional and is tested in Firefox 2 and IE6.

The approach is much similar to my previous post, as it uses iframes. But in this project, I have created everything in a single file, so all codes can be handled easily. And coder will feel that s/he is completely implementing ajax extensions, in addition to users who will have experience of partial page postback.

In this simple project, I have written code to do file upload and display all files uploaded in a listbox without doing full page postback.

asp.net ajax extension - file upload project

 

 

 

download project file

.

.

NEW: Uploading files in a GridView (Feb 20, 2008).

.

.

Read Full Post | Make a Comment ( 48 so far )

Flash Image Streaming – Zoom and Pan

Posted on March 14, 2007. Filed under: Uncategorized | Tags: , , , |

Many flash developers are unknown to this technology – image streaming in flash. Take a look at this page:
Ch√Ęteau de Chenonceau -The pantry

Using the zoom tool, I could see all that is inside the far room that you can see in this picture. I also tried to find out the time in the clock placed in the cupboard at the right side, seems to be around 1. It is not so clear, but it is because of the type of clock.

This tool is way too cool.

Take a look at another such system:
Discovery Channel :: Alien Planet
A tool to achieve this is Zoomifyer – which you can find it at http://www.zoomify.com

There are three Zoomifyer products: Zoomifyer EZ, Zoomifyer for Flash, and Zoomifyer Enterprise.

As Zoomifyer EZ is free product, I was quick to download and test it. It even was way too simpler and quick to make zoomable flash page. The software actually cuts a large image to multiple small images, a swf movie is also created and the images are internally joined together when swf movie is viewed.

This would not be much concern for general flash developers like me (although I am not into flash for quite some time now); But I think it is not the exact image streaming. The complete product Zoomifyer Enterprise (US$795) seems to provide exact image streaming solution as it mentions to have Single-file (PFF) storage and Flash Communication Server integration.

Read Full Post | Make a Comment ( 1 so far )

Mixing your javascript into ajax extensions

Posted on March 13, 2007. Filed under: Uncategorized | Tags: , , |

After you start working deep in asp.net ajax extensions, you might sometimes need to write some of your additional javascript codes, and you will need them to integrate with the ajax extension system.

For example, suppose I need to populate a GridView control by doing an ajax callback, say with a Button click. I have the GridView in a <DIV style=”position:absolute;”> element. I want to show the DIV layer after the GridView is populated at the position where button was clicked.

Sounds simple and the old story isn’t it? But if you think little more, you might find this little interesting, because for this situation you will need to write some of your own javascript code before doing ajax callback and also after the completion of callback.

So here is my simple approach:

1. First I create the GridView control inside the DIV layer. The details of GridView in this post is not necessary. I also create the required button, and I put all of them in UpdatePanel.

<asp:UpdatePanel id=”upnlMain” runat=”server”>

<ContentTemplate>

<div id=”divLayer1″ style=”position:absolute;display:none;”>
<asp:GridView id=”GridView1″ runat=”server”></GridView>
</div>

<asp:Button id=”btnShowGrid” runat=”server” Text=”Show Grid” OnClick=”btnShowGrid_Click” OnClientClick=”return ShowGrid_Start(event);” />

</ContentTemplate>

<Triggers>
<asp:AsyncPostBackTrigger ControlID=”btnShowGrid” EventName=”Click” />
</Triggers>

</asp:UpdatePanel>

Note that I have used OnClientClick event for the button, to have javascript codes to execute before the ajax call is made, I will explain the javascript function ShowGridClick() a little later.

2. Now, in the code behind I write following btnShowGrid click handler:

Protected Sub btnShowGrid_Click(ByVal sender As Object, ByVal e As EventArgs)
‘ populate the GridView here.

ScriptManager.RegisterStartupScript(btnShowGrid, btnShowGrid.GetType, “key”, “ShowGrid_End();”, True)
End Sub

Here, the code calls the shared (static) method of the ScriptManager to register the javascript code, which will be executed in client side after the callback is completed. The only code is to call the javascript funtion ShowGrid_End().

3. So, as you might have understood the simple principle for our custom javascript codes: set required variables before ajax call in function ShowGrid_Start() and finally write final codes in function ShowGrid_End(). So here is the javascript code:

<script type=”text/javascript”>

function ShowGrid_Start(e) {
// store the mouse coordinates when button was clicked.
if (document.all) {
X = window.event.clientX + document.body.scrollLeft;
Y = window.event.clientY + document.body.scrollTop;
} else {
X = e.pageX;
Y = e.pageY;
}
document.GetElementById(“divLayer1”).style.left = X;
document.GetElementById(“divLayer1”).style.top = Y;

// return true to proceed with ajax call :: returning false would not trigger it.
return true;
}
function ShowGrid_End() {
document.GetElementById(“divLayer1”).style.display = “block”;
}

</script>

Read Full Post | Make a Comment ( 3 so far )

Uploading files using asp.net ajax extensions

Posted on March 13, 2007. Filed under: Uncategorized | Tags: , , , |

The current ajax extension (Version: 1.0.61025.0) does not support file upload within the UpdatePanel. I am not so sure why, but I have heard it to be because browser security limitations. As browsers do not allow direct access to user file system via javascript codes, and due to this reason the <input type=”file”> cannot be modified by javascripts and also the details of file cannot be accessed without any activex, not working of file uploads in ajax approach is quite obvious.

But, most of us all have seen the new generation internet mailbox system, which does upload files (attachments) in background without page refresh. The method then should be ajax implementation or some other trick. I have no idea!

When GMail was in baby stage, I had heard that it uses hidden frames to implement ajax like infrastructure – due to browser security reasons. (But I think, GMail now uses ajax). Knowing this rumor, I once happened to create multiple files upload system using hidden iframe and javascripts – user would provide a list of files and they would get uploaded to the server one by one. The creation easily solved the problem of maximum file size limit, and also errors when doing large file upload.

Now, as I am onto ajax extensions and as the uploading is not working within UpdatePanel, I went to give the same approach a try. And after some good amount of time, I was able to do it. Here is my approach outline in basic form:

1. I first created an upload form in separate page which is like this (myIframe.html):
<form method="POST" target="_self" enctype="multipart/form-data" action="main.aspx">
<input type="file" name="fileUpload" />
<input type="submit" value="UPLOAD" />
</form>

2. In my main page (main.aspx), I put an iframe and loaded that page in it. I also made borders invisible so it did not look like it is an iframe.
<iframe name="iUploadFrame" src="myIframe.html" frameborder="0" onload="iUploadFrameLoad();"></iframe>

Note that I am also specifying onload event handler function of javascript. I will explain it below.

3. For testing, in main.aspx I also have UpdatePanel with a button and label like this:
<asp:UpdatePanel ID="pnlMain" runat="server">
<ContentTemplate>
<asp:Label id="lblMessage" runat="server" />
<asp:Button id="btnUploadComplted" runat="server" style="visibility:hidden;" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUploadCompleted" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

Note that I have hide the button using CSS style, but not setting visible=”False” attribute. This is because I still want to have the button html in the output document and would want to trigger the ajax callback via that button.

3. I then define the click event hander of the button in the codebehind as:
Protected Sub btnUploadCompleted_Click(s As Object, e As EventArgs)
lblMessage.Text = "UPLOAD PROCESS COMPLETED SUCCESSFULLY"
End Sub

4. Now, to save file I write following code in the code-behind:
Protected Sub Page_Load(s As Object, e As EventArgs)
If Request.Files.Count = 1 Then
' process to save file
Response.Write("SUCCESS")
Response.End()
End If
End Sub

5. Now all that we need to do is create javascript function to integrate the process into ajax implementation. The event will trigger when upload process is complete, and it will, in turn, triggers btnUploadCompleted’s click event, which is responsible for making our ajax call.
<script type="text/javascript">
function iUploadFrameLoad() {
if (window.iUploadFrame.document.body.innerHTML == "SUCCESS") {
document.forms[0].elements[btnUploadCompleted].click();
}
}
</script>

.

.

NEW: I have written a new post with complete source code for this process. View post.

.

.

NEW: Uploading files in a GridView (Feb 20, 2008).

.

.

Do write me comments and suggestions on this article.

Read Full Post | Make a Comment ( 32 so far )

Liked it here?
Why not try sites on the blogroll...