Posts

Optimize compilation for a complex projects

Image
Most of the web applications nowadays are complex applications that maybe have more than 50MB source code to deploy on the server and it will lead to a long compilation time around 3-10 minutes depends on the server resources. Some will say, it still ok to wait for the compilation since it only happens for the first time. What about require to change the source code with a very minimal code of line.? Like one line only.? Do you still love to wait 3-10 minutes? The answer is no. But how to avoid this situation. It is simple, just one line of configuration on the web.config will help to fasten compilation code (Just in time compilation). The answer is put : optimizeCompilations="true" as an attribute on the compilation element in the web.config file.

Force to download file in ASP.NET

This is an example of how to force the current HTTP Context Response to download files. Before that, you need to set a path/folder in your web application to store files that you just created or pre-set the file to download. In ASP.NET this is the way to set a path. Since we can use the tiddler("~") symbol to referring to the root with a virtual path set from IIS. string pathFile = Server.MapPath(Request.ApplicationPath); Force download method : string pathFile = Server.MapPath(Request.ApplicationPath); Response.AddHeader("Content-Type", "application/octet-stream"); Response.AddHeader("Content-Transfer-Encoding", "Binary"); Response.AddHeader("Content-disposition", "attachment; filename=\"" + yourfilename + ".csv\""); Response.WriteFile(pathFile + yourfilename + ".csv"); Response.End();

Fix issue file not upload to server with Multiview + File Upload + UpdatePanel - asp.net

Recently I have developed some modules to upload the file to the server. In my code, I have an update panel and also the multiview. Somehow the upload not working. So I thought I was not set the full postback for the upload process in the trigger section under the update panel. But actually, the full postback was set correctly. So I wonder, why the upload not working.  So I start to investigate my code, and luckily I found the solution. The solution  I just need to set enctype attribute at the form and value  multipart/form-data. This is the code I use. protected override void OnInit(EventArgs e) { base.OnInit(e); Page.Form.Attributes.Add("enctype", "multipart/form-data"); } Hopefully, this simple solution helps someone.

Jquery Mobile, document ready not fire.

Today i have experience some weird situation which i already put the alert script on my mobile html page, but the alert didn't show. The alert script not put at the homepage, but at the url provided, when click the button then will redirect current page to the new page with contain alert script. For me,this is so weird. No error on script. At the first place i though it was cache.. so i click on refresh button.. So i just assume it is cache. But after a while, it always need to refresh only show the alert message. So i start googling the problem. Some folks says need to clear  cache, close open the browser, and put some funny funny script just to clear the cache.. But still the problem exist. After keep looking, i found the answer in here :  Demo JQuery The document say, if want to put html "a" tag, need to put some attribute based on what are the requirement you want. Example : if you want to redirect the current page to the new page : <a href="newpage.html"

Example Lock Dataset in C#

This is an example of how to lock your database or prevent data in the dataset to changed (read-only dataset). In a large web application, you may have a reference table in the database, and the application no need to read on the reference table every time the application needs to get a reference. You can store the reference table in cache memory. But you afraid that the data might accidentally  changed by your code. This is the way to make your dataset lock / read-only. Lock Dataset method /// <summary> /// Makes the given DataSet read-only /// </summary> /// <param name="ds">DataSet</param> public static void LockDataSet(DataSet ds) { // Do not lock null if (ds == null) { return; } EventHandler locked = (sender, e) => { string msg = String.Format("DataSet '{0}' cannot be modified, it is read-only.", ds.DataSetName);

Passing parameter to page using Javascript

This is an example method using javascript to redirect to the searching page with a parameter from the textbox when click the submits button. Requirement JQuery library HTML <div class="input-group search-btn"> <input id="textSearch" type="text" onkeypress="keypressSearch(e);" class="form-control"> <span class="input-group-btn"> <button class="btn btn-default" onclick="return Search();return false;" type="button">SEARCH</button> </span> </div> Javascript <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript"> function Search() { var txtField = jQuery("#textSearch").val(); document.location.href = "/Search.aspx?searchtext=" + txtField + "&searchmode=anyword&qu

Splits the camel cased input text into separate words.

Image
This is an example method to split "Camel Cased" into separated words. Example Camel Cased ThisIsOneExample TomorrowIsWhatDay ThisIsAnotherExample ASPX Page <asp:Label ID="Label1" runat="server" Text="Camel Words"></asp:Label>: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <br /> <asp:Button ID="Button1" runat="server" Text="Convert" onclick="Button1_Click" /> <br /> Preview : <asp:Literal ID="Literal1" runat="server"></asp:Literal> <br /> <p>&nbsp;</p> <p>&nbsp;</p> Code Behind protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string camelWords = TextBox1.Text; IEnumerable<string> _words = Sp