Thursday, October 24, 2013

Useful links for .NET Programmer

ReportViewer 2012 AND IIS 7
ReportViewer 2012 AND IIS 7 Reference #1
ReportViewer 2012 AND IIS 7 Reference #2

Logging Error in ASP.NET
Logging Error in ASP.NET Reference 1
Logging Error in ASP.NET Reference 2
Logging Error in ASP.NET Reference 3
Logging Error in ASP.NET Reference 4
Logging Error in ASP.NET Reference 5

Hover Menu Extender sample
Hover Menu Extender sample

Remove annoying arrow at menu
Remove annoying arrow at menu

SKyDrive Sample Codes
SKyDrive Sample Codes Reference 1
SKyDrive Sample Codes Reference 2

HoverMenuExtender
HoverMenuExtender Reference 1
HoverMenuExtender Reference 2
HoverMenuExtender Reference 3
HoverMenuExtender Reference 4

Showing Images on MouseOver
Showing Images on MouseOver

Cache, Session and Viewstate
 Cache, Session and Viewstate

Loading Related Entities
Loading Related Entities

 ASP.NET Session Timeout
ASP.NET Session Timeout

 ASP.NET Viewstate
 ASP.NET Viewstate Reference 1
  ASP.NET Viewstate Reference 2

Cell padding
Cell padding

vertical align css 3
vertical align css 3

Ajax-Based JavaScript File Uploader with Progress Bar
 Ajax-Based JavaScript File Uploader with Progress Bar

 jQuery File Upload Plugin
jQuery File Upload Plugin

ASP.NET File Upload with Progress Bar
ASP.NET File Upload with Progress Bar

FileUpload
FileUpload Reference 1
FileUpload Reference 2
FileUpload Reference 3

 flex container
 flex container

Chosen Plugin Dropdownlist?
Chosen Plugin Dropdownlist?

Textbox Autocomplete
Textbox Autocomplete

 ASp.NEt Autocomplete Dropdownlist
 ASp.NEt Autocomplete Dropdownlist

Validator for Checkboxlist references:
Validator for Checkboxlist References 1
Validator for Checkboxlist References 2
Validator for Checkboxlist References 3
Validator for Checkboxlist References 4

Guid password generator
Guid Password Generator

Monday, August 19, 2013

Migrating old source code of Visual Studio 2010 to Visual Studio 2012

Step 1: Enable nuget restore. Find and click on Project then find and click enable nuget restore.

Step 2: Manage nuget packages and install entityframework and ajaxcontroltoolkit.

Step 3. Download and install ajaxcontroltoolkit 4.5.

Step 4: Click on Toolbox then choose item, browse and find AjaxControlToolkit.dll version 4.5.

Step 5: Add reference to all dll that you need in your project and can be found here, C:\Program Files (x86)\Microsoft Visual Studio 11.0\. For example,
Microsoft.ReportViewer.Common
Microsoft.ReportViewer.WebForms
System.Data.Entity

Step 6: Select a page to set as start page.

Step 7: Replace the following align or valign with vertical and text-align respectively.
Refer to this link,
 My other blog

Step 8: There are items to change in css 3 from css 1, like cursor:hand to cursor:pointer.
Browser Support
To align right,
click here

Step 9: To deploy or publish the web application. Please refer to the link below,
Reference 1
Reference 2
Reference 3
Reference 4
Reference 5

Step 10: Check for any missing dll. If you cannot find some of them, refer to this link below,
Reference 1

Step 11: To position two column table in the center at the top menu, add this css to menu.css file. .wrapper { position: absolute; left: 50%; margin-left: -70px; } the idea came from this link,
Align Contents

Step 12: When you wish to insert a image as a background, insert into a css file, this css below, background: url(../Images/ERRPAGE.png) center no-repeat;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
background-size: auto auto;
Reference used:
background size
vertical centering

Step 13: If you receive an error message "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack", apply this code before your redirect to error page like this code below,
if (ex.Message.StartsWith("Thread") == false)
{
Session["ErrorMessage"] = ex.Message;
Response.Redirect("~/Forms/Error.aspx", false);
}
Reference used for step 13,
Reference used

Step 14: to change the color of the scrollbar of a panel, use the link below,
Bar color
CSS Tutorial
There is no direct way of changing color of scrollbar in a treeview control unless you create new custom treeview control.

Step 15: In case you have this javascript error message "0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.", you can insert this meta tag in the master page,
 <meta http-equiv="X-UA-Compatible" content="IE=9" />
Step 16: To enable clicking on word displayed to expand the tree. Set the property SelectAction to Expand. To display the treeview in unexpanded format. Set the property Expanded to False.
<asp:TreeNode Text="Transaction" Value="Process" ImageUrl="~/Images/folder.png" Expanded="false" SelectAction="Expand" >
Step 17: To remove the default arrows that appear in the ASP.NET Menu Control. Set the StaticEnableDefaultPopOutImage property to False. This property is responsible for the default arrows that appear in the ASP.NET Menu control. To remove the default arrows that appear in the ASP.NET menu items. Set the DynamicEnableDefaultPopOutImage property to False. This property gets or sets a value indicating whether the built-in image that indicates that a dynamic menu item has a submenu is displayed.

Reference used for step 17:
Reference for DynamicEnableDefaultPopOutImage
Reference for StaticEnableDefaultPopOutImage
Another Reference for StaticEnableDefaultPopOutImage

Step 18: Fixing the displaying of rdlc inside a report viewer 2012 using IIS 7. Please refer to this link to add handler mappings at iis.

Step 19: To display Elmah.axd, allow remote access by setting allowRemoteAccess from false to true at web config file. And add a file extension to allow . Find and click Request Filtering. Find and click Allow file name extension link. Type in .axd at File name extension and then click OK.

Step 20: To insert space between menu and submenu, put some value at DynamicMenuItemStyle-HorizontalPadding  property.
Reference used for step 20

Migrating from Visual Studio 2010 to Visual Studio 2012
Reference 1
Reference 2
Reference 3
Reference 4
Reference 5
Reference 6

Monday, July 8, 2013

Migrating to HTML 5 using ASP.NET 4.5

Let us say, you have previous aspx page that you copy and paste. You use HTML 5 in visual studio 2012. When you try to compile, it will give you a compile error.
Please change align="left" to style="text-align:left". Please change align="right" to style="text-align:right". Please change align="center" to style="text-align:center".

Migrating from EF 4 to EF 4.5

If you do have a previous class that uses entity framework in visual studio 2010. Then you need to create the same class using visual studio 2012. When you try to copy and paste into the new class. Then compile it, it will give you an error. In visual studio 2010 Addto<tablename> method and DeleteObject method no longer exist. Please use <tablename>.Add method and <tablename>.Remove method respectively. For insert, user add method and for delete, use remove method.

Tuesday, May 28, 2013

How to validate an Ajax control combo box has item selected or not?



First, you need to insert beside the combo box a custom validator like this,

<asp:CustomValidator ID="cv" runat="server" ControlToValidate="cmb" Text="*" ForeColor="Red" ValidateEmptyText="true" ClientValidationFunction="CustomValidator" Display="Dynamic" ErrorMessage="combo box is required!" CssClass="validator" ValidationGroup="valGrp"></asp:CustomValidator>

If your combo box default selected value is an empty string then you need to add a function inside a <script type="text/javascript"> like this,

    function CustomValidator(s, e) {
        if ($find(s.controltovalidate)._textBoxControl.value == "") {
            e.IsValid = false;
        }
    }

If your combo box default value of “Please select” then you need to add a function inside a <script type="text/javascript”> like this,

    function CustomValidator(s, e) {
        if ($find(s.controltovalidate)._textBoxControl.value == "Please select") {
            e.IsValid = false;
        }
    }

References used:

Monday, May 13, 2013

How fix the column width in a gridview at insert tooltip in each cell in Asp.net 4?




If you need to set the width of each column in a gridview control,  If the column is just to display and no editing needed. You can like this,

<asp:TemplateField HeaderText="column Name" SortExpression="fieldname">
<HeaderTemplate>
       <div style="text-align:center;background-color:#41627E;color:White;font-size:x-small;font-weight:bold;overflow: hidden;white-space: nowrap;width: 50px;" >column Name</div>
</HeaderTemplate>
<ItemTemplate>
<div style="font-size:xx-small;white-space:nowrap;overflow: hidden;text-align:left;font-weight:600;font-family:Tahoma;width: 50px;" >
 <asp:Label ID="lblGridColumnName" runat="server" Text='<%# Bind("fieldname") %>' ></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>


But if there is a editing to be done, you need to do like this,

<asp:TemplateField HeaderText="column Name" SortExpression="fieldname">
<HeaderTemplate>
<div style="text-align:center;background-color:#41627E;color:White;font-size:x-small;font-weight:bold;overflow: hidden;white-space: nowrap;width: 40px;" >column name</div>
</HeaderTemplate>
<ItemTemplate>
<div style="font-size:xx-small;white-space:nowrap;overflow: hidden;text-align:left;font-weight:600;font-family:Tahoma;width: 40px;" >
<asp:Label ID="lblGridColumnName" runat="server" Text='<%# Bind("fieldname", "{0:n0}") %>'></asp:Label>
</div>
</ItemTemplate>
<EditItemTemplate>
              <asp:TextBox ID="txtGridColumnName" runat="server" Text='<%# Eval("fieldname", "{0:n0}") %>' Width="50px" CssClass="cssclass" />
       </EditItemTemplate>
</asp:TemplateField>


If you need insert a tooltip for each cell inside a gridview, you need to set each column tooltip. You can do like this,

protected void gv_DataBound(object sender, EventArgs e)
{
Label lbl = new Label();
foreach (GridViewRow rv in gv.Rows)
{
lbl = (Label)rv.FindControl("lblGridColumnName ");
rv.Cells[1].ToolTip = lbl == null ? string.Empty : lbl.Text;
}
}

Wednesday, October 10, 2012

How to manipulate back button in ASP.NET 4?

After searching a lot of references. I have came to a conclusion that you can only prevent user from accessing the previous page is thru javascript window history. You can not manipulate the forward button but only the back button. There are many ways to do it, if you really want to manipulate both button is to clear cache like this,
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
Response.Expires = 0;
Response.CacheControl = “no-cache”;

To manipulate the previous page (back button) is thru this way,

<script type="text/javascript" language="javascript">
function DeleteHistory() {
window.history.go('Default.aspx');
}
setTimeout("DeleteHistory()", 1000);
window.onunload = function () { DeleteHistory(); };
</script>

Here are references that I have used:
Reference 1
Reference 2
Reference 3
Reference 4
Reference 5
Reference 6
Reference 7
Reference 8
Reference 9
Reference 10
Reference 11

Javascript back button asp.net
Reference 12
Reference 13
Reference 14
Reference 15
Reference 16
Reference 17
Reference 18
Reference 19

Tuesday, May 8, 2012

Optimize performance of your Entity Framework 4 on Client Side


If you want to improve the perforamance of your entity framework in client side, you can use Cache from
System.Web.Caching.Cache object. If you like to reset values,
Cache.Remove("Name of your Cache");
If you wish to store the value to a cache,
if (Cache.Get("Name of your Cache") == null)
    Cache.Insert("Name of your Cache", object);
Where your object can be dataset or datatable or list.
You can determine which part of your code that needs to refactor your existing code using Entity Framework Profiler.
Entity Framework Profiler
Reference 1
Reference 2
Reference 3
Reference 4
Reference 5
Reference 6
Reference 7
Reference 8
Reference 9
Reference 10
Reference 11
Reference 12
Reference 13
Reference 14

Thursday, April 12, 2012

Troubleshooting your rdlc inside Visual Studio 2010.

In order to troubleshoot your rdlc inside Visual Studio 2010.
Problem: how to make table invisible when there is no row.

Solution:  Set the expression for the row,
=IIF(Fields!BILLER.Value is nothing, true, false)
Step 1: Right click the tablix, choose and click row visibility.
Step 2: Choose and click the button beside “Show or hide based on an expression”.
Step 3: Enter the expression, =IIF(Fields!BILLER.Value is nothing, true, false).

Problem 2: How to display the image inside the report viewer.

Solution: You need to set the UI culture and culture for an individual page, set the Culture and UICulture attributes of the @ Page directive, as shown in the following example:
<%@ Page UICulture="es" Culture="es-MX" %>
To insert image on the report itself.
Step 1: Right click and choose insert then choose and click on image.
Step 2: Click on import button.
Step 3: Choose and click on the image.

Problem 3: How to create a variable that will make computations, like quantity multiply price equals sales.

Solution:
Step 1: Find and Click on Report Properties.
Step 2: Find and click onVariables.
Step 3: Click Add Button.
Step 4: Enter your chosen name. Then click on “fx” button.
Step 5: Enter your expression after the equal sign.

References used:
Reference 1
Reference 2
References 3
Reference 4
Reference 5
Reference 6
Reference 7
Reference 8
Reference 9
Note: I will include the images in this post next time.