ASP.NET, it’s Perfomance and JavaScript
When creating a solution with ASP.NET we should shift our mind. Most of the component make our life easier, I bit supprise when a developer don’t know SqlObjectDataSource / ObjectDataSource, which a valuable component that should be use when you’re going to ASP.NET 2.0.
The presentation is presentation layer, why don’t keep it that way?. I am not hardcore programmer like the mighty C++ programmer whom able to program in unmanaged code / MFC. Those people are top notch even compare to Java programmer. I am positioning my self as practitioner programmer, most of my time just think the logic not how to manage memory and use threading especially working in ASP.NET or PHP environment.
HTTP is stateless, is still stateless and that’s the beauty of HTTP. ASP.NET save the state using their own method like VIEW STATE which enlarge the HTML output. If you’re great developer you won’t think to much how to get rid of VIEW STATE since it’s very usefull in ASP.NET 2.0, why don’t make a setup to the IIS and make something called Compression being enabled?. It cost less and efficient. OSI layer must keep in our mind as we move on to Web programming, Web Server have big influences to Web.
Okay, I just want to share that I get bit confused when mixing non ASP control a.k.a HTML form component like <input> to be JS controller for other ASP control. Hell, if you working with non MASTER PAGE (this ASP.NET 2.0 feature), you will be happy ever after. You know that ASP.NET would render all Response.Write BEFORE touching the component, it’s beyond of Page_Load Event and PostBack. Okay, I give you an example :
<Asp:textbox id=”textboxUser” runat=”server”/> <input type=”button” name=”xyz” onclick=”ShowUserName(‘textboxUser’)” />
Let’s pretend that we use Master Page. Okay we have code in Javascript (we use IE) :
<script type=”text/javascript”>
function ShowUserName(controller) {
var obj = document.getElementById(controller);
window.alert(obj.value);
}
You will get error … yes, you will get error!. Why? because we using MasterPage, so the real ID is not textBoxUser but ctl00_ContentPlaceHolder1_textBoxUser. You could specify it manually, like :
<Asp:textbox id=”textboxUser” runat=”server”/> <input type=”button” name=”xyz” onclick=”ShowUserName(‘ctl00_ContentPlaceHolder1_textboxUser’)” />
but, this isn’t good because sometime you want rename the ContentPlaceHolder1 into ContentPlaceHolderXYZ, then you will get crash. You know what will be happen next, you must rewrite ALL control ID in your onclick event. There’s some elegant way, and you won’t deal with Response.Write(). You could use <%= textboxUser.ClientID %> and we need to add this to our input button onclick event :
<Asp:textbox id=”textboxUser” runat=”server”/> <input type=”button” name=”xyz” onclick=”ShowUserName(‘<%= textboxUser.ClientID %>’)” />
and you’re done. So, if you bos doesn’t like postback and I don’t know why they think postback will be happen when OnClientClick is rendered as OnClick at the browser which doesn’t create a postback, and love to use the hardway. Please don’t hesitate to show up your self to you bos that you could done a wrecking ASP.NET 2.0 fundamental.
Don’t think that Ajax will create a “Wow” functional experience, it could wreck. If you’re running business a dollar means a lot, you should see this page http://ajaxian.com/archives/accessibility-use-ajax-get-sued. AJAX will help user, but for high transaction business, leave it to HTML Form, using PostBack will save your day. I will be safer, traditional is old-school but safer!.
Happy hacking the ASP.NET 2.0 and wait a second, you will go to ASP.NET 3.5. Tell your mate at your IT/IS Solution company who love DataList especially in Indonesia to begin learning about GridView and the DataSources component. ASP.NET is growing. And tell them not to use CodeSmith which is confusing, because they never write the code and force them to use ObjectDataSource which built-in in your Visual Studio 2005. I recommend SubSonic rather than CodeSmith as DAL.
How to check your Windows Live Mail using Thunderbird
Mozilla Thunderbird is an amazing email client. I love to keep my email messages at one place and staying away from application which need installation when I must reinstall my Windows. I found Thunderbird portable to solve the problem and the best part of being portable is we could install it on an USB thumb-drive.
I want to access my Hotmail Windows Live Mail with an email client. Microsoft recently release an beta version of Windows Live Mail email client, and it didn’t work at all. Okay, I must open an internet browser and checking my email.
Fortunately, Thunderbird have an extension which called WebMail extension. It help users to accessing famous webbased email provider like Yahoo!, Hotmail, AOL, Lycos, and many more. You could check whether if your web-based email provider also supported by this extension.
The installation is pretty easy. I assume you don’t have Thunderbird, please do this step :
- Download Mozilla ThunderBird Portable
- Download WebMail Extension
- Download Hotmail extension or othe optional extension.
- Install Mozilla ThunderBird Portable
- Installing WebMail Extension and restart
To install WebMail Extension, you must open Thunderbird and point to tools > add ons > install. Then select your .xpi file which you had downloaded from Webmail Extension site.
- Installing Hotmail Extension and restart.
Do the same method with previous point to install Hotmail Extension. This will help you downloading your email on Windows Live Mail. - Back to Addons menu / windows, then check all required port by the Web Mail extension
- Setting up your web-based account on Mozilla Thunderbird.
The steps would be same with creating new account for POP3 or IMAP account and you must specify username with full email address. On the first window you must select Web Mail as your choice to access your email. - Configure your Hotmail Extension to support Windows Live
Check Windows Live as your carrier, if you don’t do this mostly you will failed to fetch email from your Hotmail Account. - Getting your web-based email messages and Enjoy!
You will ask, where the screenshot?. The screenshot crashing my blog engine … hahaha. Really!
WishList: Own a mySQL “superduper” extension on my PHP production server
I hope much from PHP 5 and MySQL 5 when developing a application which provide summary reports. The constraint is coming from the requirement. OK, I make the code with full PHP 5 and MySQL 5 features.
I have 3 master tables which have one to many relationship. I am looking for feature that could combine the three table, and I do INNER JOIN on those 3 tables. I should retype this as variable in PHP code, which is hard to read and I should send several bytes to MySQL Server.
Description of SQL code that I build (this is fake, i am trying to give a case):
SELECT A.User, B.Thread, B.ThreadName, C.Topic FROM myUsers AS a
INNER JOIN myThread as B ON a.id_user = b.id_user
INNER JOIN myTopic AS C ON b.id_thread = c.id_thread;
Maybe you ask, why I don’t use asterisk near SELECT (example SELECT * FROM)? because I don’t need all fields and I want perfomance!. For queries like this the asterisk giving big impact perfomance output. Can you Imagine how long the query is? and when needed the WHERE clause also be used on the queries.
Oh yeah, you might said . Just use variables in PHP!. Heck, the matter is not that simple, I want 75% process is held on mySQL server because I need computing and processing to currency with SUM, MAX, MIN, and so on so forth.
The purpose is PHP + HTML become the presentation layer. I would use stored procedure when knowing have to create a summary, but I was develop too far which give me effort and time to edit all mySQL command into mySQLi. I should consider to use mySQLi extension for next projects. The disadvantage to use mySQLi is run slow for some machine.
According to PHP manual, mySQLi could support for mySQL server version 4.1 and above. Which help me to use Store Procedure. I remember that mySQL have connector, because I am using it in .NET too. I visit mySQL developer website and I found no connector for mySQL 5.0.45. The stories goes on and I am looking the best way to make the process faster.
I really want to use VIEW feature in mySQL to shortening the long code like that, so I just call
SELECT * FROM myViewTable
and giving the same result as the previous query. Well, the code is finished and I use it for fun in mysql client console. I read that VIEW have limitation, so I don’t use it.
Now, the code is working good but often make the CPU work hard, it utilize around 84% – 100% only for mySQL. In some case, maximum timeout is arise. This is happen because the bootleneck between PHP engine and mySQL server, so user must wait a moment when generating report in real time. Increasing maximum time for processing and memory available for php engine is just for temporarily solution.
Is there any mySQL “superduper” extension?. One conclusion has been made:The production server will always need continuously patched with new version of connector to make the availability of the web application reached.
Another question is came up to the case, “Are LAMP ready for Enterprise and OLAP application?”.
PHP Trick to generate variables from FORM
I hate to write code, really! hehehe … I often hand-code my code, even in Visual Studio! Heck, I don’t know why I love this style of coding. The one that I don’t code is when approching Database, I often use tools to help me generate code, just say PHPMyAdmin.
Sometime, I hate to write code especially when dealing with something called “Form Gathering” with any method like GET/POST. If I handle only one to six data, I will write it happlily ever after. I was create a webform consisting 27 inputs, yeah, 27 inputs. I assume you understand about HTML Form.
PHP is very handy programming engine and I love to make a shortcut to deal with those 27 inputs. I create a code which gathering all inputs and my PHP code create another code.
This is the code :
<?php
foreach($_POST as $key => $value) {
echo $key.' = $_POST["'.$key.'"]; <br />';
}
?>
I don’t like escaping too much so I use echo and concation operator (the dot). So what the code doing?
- $_POST is an array and contain collections of element in form. So, we could create loop to access the individual item. If you use GET method, please change the $_POST into $_GET.
- You may be wondering why I create $value variable which I never be use. The reason is very simple, I just want to know the “name” of form elements (input) not the value.
- Echoing the the line to create a new code that I could copy paste into another PHP File.
Creating little tool like this often help developer increase his/her productivity. Why? because you can reuse it for next projects.
Happy Programming with PHP!.
ASP.NET Typed Dataset Common Problem
If you’re new to ASP.NET you will introduced to Typed Dataset, what the heck is that? It’s feature which available in Visual Studio. I assume you already understand how to create Typed Dataset.
Most of programmer tell me that Typed Dataset is very fragile to any modification. Yes, indeed it is. Why I have such conclusion? It started when I starting to use Typed Dataset. The famous “Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.” error will make you desperate and force you to write a class to accesing your table. If you think it’s simpler to write your own code than automatically generated by ASP.net, please do so. It will save your time a lot.
Well, some people will find the answer why it happen to their Typed Dataset. Typed Dataset saves our time to write a Data Access Layer (DAL) class, really!. I just run a wizard the voila you could use it in any database component in your Visual Studio toolbox. Okay, I admit it’s not easy when you found an error in dataset. Okay, let’s start!
First, I found that we must consistent in any SELECT command to query (TableAdapter). Let’s take simple case, you start with this SELECT command :
SELECT username, realname FROM myUsers
When you want to filter using WHERE clause for the user by userID then your query must like this :
SELECT username, realname FROM myUsers WHERE userID = @userID
Did you see what the same? yes! the field must exact like the first query when we create new TableAdapter. Why? it will save you from unnecessary error. I don’t know the technical reason, because this tool is really complex.
Secondly, stay away from Table Changes. When developing process often we add or change the column in a table, because many reasons. Often people meet the famous error that I mention above after changing the table and the corresponding DataTable/Table Adapter in Dataset. By trial and error I found several solution to this :
- You could always change the MaxLength on VarChar / NVarchar to restrict user when inputing data to database.
- If you want varchar data type to ntext / text, please user varchar(MAX) / NVarChar(MAX). Then set the MaxLength with -1 value to allow release the length restriction. You will void the famouse error by stay using NVARCHAR(MAX) rather than NTEXT.
- Plan your database and the queries to heart before starting to build Typed DataSet … hehehe. What else better?
Thridly, DataType Conversion Error. The error often show like “System.InvalidCastException: Unable to cast object of type ‘System.DBNull’ to type ‘System.String’.“. How you get rid of this? don’t worry, it’s ASP.NET fault not the DataSet. You could this :
- Create a variable to store the data if exists, fill the variable with null.
- Check your field value
Example in C# :
string _realName = null;
If(!myUsers.IsRealNameNull()) _realName = myUsers.RealName;
labelRealName.Text = _realName;
myUsers is the TableAdapter, and IsRealNameNull() was automatically generated by ASP.NET.
Hopes this journal will help you out, I found many problem like this. Microsoft must fixing this Typed Dataset complexity into simpler form that human and developer understood.
Happy Programming, Folks!.
