Archive

Posts Tagged ‘ASP.NET’

Display confirm message

April 18, 2006 13 comments

In windows application, when user want to delete any information, usually a confirm message box’ll be launched, so if user really want to delete they must confirm this action again. In ASP.NET we can easily do the same in two ways:

1. Register confirm action inside the PreRender event to add javascript into the client side so it’ll operate when user click on the button.

private void Page_PreRender(object sender, EventArgs e)
{
   btnDelete.Attributes.Add("OnClick", "return confirm('Do you really want to delete this row? No undo action is available')");
}

2. Add  “OnClientClick” event inside HTML code like this:

<asp:Button ID="btnDelete" runat="server" OnClientClick="javascript:return confirm('Do you really want to delete this row? No undo action is available');" />

Hope this help you!!!

Categories: ASP.NET Tags:

A simple atlas example

April 13, 2006 3 comments

To day, when we say about new technology in web application everyone’ll say about AJAX and its related product. There is some frameworks out there that we can use to apply AJAX into your website, EX: ATLAS, ANTHEM, AJAX Magixc. Each of them has its own features, advantages and disadvantages. You can find more information about them on internet

So now i just want to show you an example using one of the above framework called ATLAS (I introduced you about this in my previous article). ATLAS is a product developed by Microsoft team based on AJAX concept.

It is built into controls that we can easy drag and drop on our IDE, one of them is <atlas:UpdatePanel>

The main purpose of AJAX is to refresh each part of webpage seperately. That means postback only one area insteas of entire page, so any control that we want to postback just put it inside <atlas:UpdatePanel>

before starting, you must sure that you have copy ScriptLibrary and put it in your project. You should also add reference to the Microsoft.Web.Atlas.dll

<atlas:UpdatePanel ID="uc" runat="server">
   <ContentTemplate>
      <table width="100%" border="0″ cellspacing="0″ cellpadding="0″>
         <tr>
            <td width="56%" style="height: 158px" valign="top">
            <asp:TreeView ID="trvChuDe" runat="server"
                 OnSelectedNodeChanged="trvChuDe_SelectedNodeChanged"
                 OnTreeNodeCollapsed="trvChuDe_TreeNodeCollapsed"
                 OnTreeNodeExpanded="trvChuDe_TreeNodeExpanded">
            </asp:TreeView>
            </td>
            <td style="height: 158px" valign="top">
            <asp:Label ID="lblRightData" runat="server"></asp:Label>
            </td>
         </tr>
      </table>
   </ContentTemplate>
   <Triggers>
      <atlas:ControlEventTrigger ControlID="btnLoad" EventName="Click"/>
</Triggers>
</atlas:UpdatePanel>

As you can see that i want the treeview to update only itself so i put it inside the <atlas:UpdatePanel> tag. This tag includes two child tag:
+ <ContentTemplate>: where you put you control, html code that you want to postback when refreshing

+ <Triggers>: if you want that when the user click on a button, the content’ll be fill in the treeview with no entire page refresh happen, so you must specify the source control id and what event makes it happen by using two attributes: ControlID and EventName. This tag not only use for button, but any control that can make a postback event.

After you have done, before you can start, remember to but the below tag inside the <head></head> tag or any positions inside <form> tag as a declaration. If you choose to put the below tag inside the <head></head> tag, make sure that this tag is runat server

<atlas:ScriptManager ID="scriptManager" EnablePartialRendering="true" runat="server" />

Now you can run your webpage to see what happen. Amazing!!..

Although in ASP.NET 2.0, some actions in treeview have been used AJAX (just do inside and you can not see it. ASP.NET team has configured it as an normal event). But in some case you must apply this way

Categories: ASP.NET Tags:

Atlas, web technology for the future

April 13, 2006 Leave a comment

One of the bad thing when we browse web pages is its postback event. That means at anytime we want to change information on a web page, a postback event’ll happen and all the webpage’ll be refreshed, this problem make the web become not friendly as windows application.

There are many developers out there who are trying to handle this problem but no one get into the best result until a concept call “AJAX” appears. This stands for Asynchronous JavaScript And XML, Ajax is an approach to creating responsive and interactive webpage that laverages the capabilities built into browsers.The core about Ajax is asynchronous, it using XMLHTTP object to transfer object along the web. This object has already appeared some years before but it’s just used for IE browser. Nowaday, it has been plug-in most of the popular browsers like IE, Firefox, Safari so i think it lays the foundation for Ajax to develope. Using Ajax you can make an update data only in an area on a page, not all web page as before

Based on Ajax, Mircrosoft has recently announced a framework called ATLAS, this concept is developed based on Ajax, it used XMLHTTP to builtd a framework in the side of client. This framework provide a object-oriented approach, allows you to make class, event handling, data type, object serialization (browser specified). Especially drag drop, popup, databoud listview control, Navigation control… something that is difficult to implement at the server-side application.

Microsoft, Google, Amazone has used Ajax in their website and recently is Yahoo. They has contruct their own controls, component and integrated them into website based on Ajax, you can try it at : http://www.live.com, http://www.maps.google.com, …

Because ATLAS framework is still under-contruction and test. You can keep track of its information at http://www.atlas.asp.net and its document with many examples at http://www.atlas.asp.net/docs All for free and waiting for you

Categories: ASP.NET Tags:

using httpHandler in asp.net 2.0

April 13, 2006 2 comments

Sometime you don’t want to use the default ASP.NET handler and want to write your own. This can easy do just some line of code. For example i have a class which is used to get a file from database and response a “Save As” dialog so user can choose to download the content to client:

download.my

using System.Web;
namespace MyHandler
{
   public class Download
   {
      public void ProcessRequest (HttpContext context) {
         FileAttach file = new FileAttach();//Get id from the request
         file.ID = Int32.Parse(Request.QueryString["id"]);
         file.ConnectionString = ConfigurationManager.ConnectionStrings["myConnection"].ConnectionString;
         // Start getting the file content from database
         file.GetFileContent();
         // Write out the attachmentServer.ScriptTimeout = 600;
         Response.Buffer = true;Response.Clear();
         Response.ContentType = "application/octet-stream";Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.FileName + "\";");
         Response.AddHeader("Content-Length", file.Content.Length.ToString());Response.BinaryWrite(file.Content);

         // End the response and send the output to clientResponse.End();
      }
      public bool IsReusable {
         get { return true; }
      }
   }
}

After you have created the file, then you have two choices to save this file. First you can make a Class Library project, add “download.my” file, compile it into an assmbly then from the web project chooose add reference to new dll . Second you can add “download.my” in the App_Code directory, this directory is a new concept in ASP.NET 2.0. Any file inside it’ll be dynamicly compiled into an .dll.

To use the handler, in Web.Config we must specify an introduction so ASP.NET can use to handle the request:

<httpHandlers>
<add verb="*" path="download.my" type="MyHandler.Download, App_Code" />
</httpHandlers>

After you have confiured all the above information. You can call the handler by using :

<a href="download.my?id=<%# Eval("Id")%>">aaaaaaaaa</a>

In the other hand, you can use a Generic Handler (.ashx) to write the content for our handler. if you use this file you need not to write anything in Web.Config. This file is default understood by asp.net as a handler, and the syntax is the same when calling

<a href="download.ashx?id=<%# Eval("Id")%>">aaaaaaaaa</a>

If you still want to use your class and using Generic Handler is the handler link you just change the information in the tag header

<%@ WebHandler Language="C#" Class="MyHandler.Download" %>

where MyHandler is the namespace and Download is class name

Categories: ASP.NET Tags: