12 September 2014

Visual Studio editor show dots in blank spaces?


In my Visual Studio text editor. All my blank spaces are replaced by a "."

public class Employee
{
  string name;
}

looks like this

public..class..Employee..........................
{..................
..string.name;...................
}.....................

Solution:-
To remove dots follow the below methods.

Method 1:- 
       Go to

            Edit -> Advanced -> View White Spaces

Method 2:-
           Press Ctrl+R, Ctrl+W

26 June 2012

Invoke custom method in Crystal report default print button click event


We have requirement is when i click on default crystal report print button, it will open printoptions window, when i select/click the Ok button, on button click event i want to insert data into the database(Call custom method). we tried so many way at last we got the solution for that as shown in bellow link
My Link: http://dotnetgoutham.blogspot.in/2012/06/get-control-name-in-pageload-event.html
Step 1:
 public string GetPostBackControlId(Page page)
    {
        if (!page.IsPostBack)
            return string.Empty;


        Control control = null;
        // first we will check the "__EVENTTARGET" because if post back made by the controls
        // which used "_doPostBack" function also available in Request.Form collection.
        string controlName = page.Request.Params["__EVENTTARGET"];
        if (!String.IsNullOrEmpty(controlName))
        {
            control = page.FindControl(controlName);
        }
        else
        {
            // if __EVENTTARGET is null, the control is a button type and we need to
            // iterate over the form collection to find it


            // ReSharper disable TooWideLocalVariableScope
            string controlId;
            Control foundControl;
            // ReSharper restore TooWideLocalVariableScope


            foreach (string ctl in page.Request.Form)
            {
                // handle ImageButton they having an additional "quasi-property" 
                // in their Id which identifies mouse x and y coordinates
                if (ctl.EndsWith(".x") || ctl.EndsWith(".y"))
                {
                    controlId = ctl.Substring(0, ctl.Length - 2);
                    foundControl = page.FindControl(controlId);
                }
                else
                {
                    foundControl = page.FindControl(ctl);
                }


                if (!(foundControl is Button || foundControl is ImageButton)) continue;


                control = foundControl;
                //hdPrintValue.Value = control.ID;
                Session["HiddenValue"] = ctl.Substring(ctl.Length - 7, 5);
                break;
            }
        }
        return control == null ? String.Empty : control.ID;
    }
Step 2:
        string str = GetPostBackControlId(this.Page);
        if (Session["HiddenValue"] != null)
        {
            if (Session["HiddenValue"].ToString() == "ctl01" && str == "CrystalReportViewer1")
            {
                //ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "ShowMessage", "alert('Updated Successfully');", true);
                try
                {
                    //Call custom Method() here....
                }
                catch (Exception ex)
                {
                   
                }
            }
        }

Get control name in Page_Load event which make the post back



Need to know which specific control posted back to your page? (Original article at http://geekswithblogs.net/mahesh/archive/2006/06/27/83264.aspx)
/// <summary>
/// Gets the ID of the post back control.
/// </summary>
/// <param name = "page">The page.</param>
/// <returns></returns>
public static string GetPostBackControlId(this Page page)
{
    if (!page.IsPostBack)
        return string.Empty;
    Control control = null;
    // first we will check the "__EVENTTARGET" because if post back made by the controls
    // which used "_doPostBack" function also available in Request.Form collection.
    string controlName = page.Request.Params["__EVENTTARGET"];
    if (!String.IsNullOrEmpty(controlName))
    {
        control = page.FindControl(controlName);
    }
    else
    {
        // if __EVENTTARGET is null, the control is a button type and we need to
        // iterate over the form collection to find it
        // ReSharper disable TooWideLocalVariableScope
        string controlId;
        Control foundControl;
        // ReSharper restore TooWideLocalVariableScope
        foreach (string ctl in page.Request.Form)
        {
            // handle ImageButton they having an additional "quasi-property" 
            // in their Id which identifies mouse x and y coordinates
            if (ctl.EndsWith(".x") || ctl.EndsWith(".y"))
            {
                controlId = ctl.Substring(0, ctl.Length - 2);
                foundControl = page.FindControl(controlId);
            }
            else
            {
                foundControl = page.FindControl(ctl);
            }


            if (!(foundControl is Button || foundControl is ImageButton)) continue;


            control = foundControl;
            break;
        }
    }
    return control == null ? String.Empty : control.ID;
}


If you are using master pages, simply add this to the master.cs file and where you need to call the method use the following code:
MasterPage masterPage = (MasterPage)Page.Master; // where MasterPage is the class name
 Control rep = masterPage.getPostBackControlName();
 if (rep.Parent.Parent.ID == "rpRegion")// only if postback is the regions control
 GetSelectedRegion();

08 June 2012

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 
Use <%# this.txtCompany.ClientID %> to replace <%= this.txtCompany.ClientID %> to fix the problem.

Once those changes are done then run the application if your not getting the values of controls(getting balnk ("") value instead of Client id) then follow the below step.

Re-place (<%# ... %>) with (<%= ...%>) and put your script from "head" tag to "body" tag.


Ref Link:- 
http://www.west-wind.com/weblog/posts/2006/May/27/The-Controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-ie-
http://www.dotnet-tips.com/2006/09/controls-collection-cannot-be-modified.html

30 May 2012

Temporary table issue in RDLC

I have just created a RDLC report using a Stored Procedure, which uses a temporary table.  I am getting error "Could not generate a list of fields for the query. Invalid object name '#Tablename'".  To fix this add below statement in Stored Procedure before creating temporary tables.
"SET FMTONLY OFF"
Make your temp table a permanent one and do the management of it yourself (deleting rows after use etc). This could be faster as well as indexable and you can add keys as needed to ensure integrity. It can also act as a cache for long running queries.


18 May 2012

Data Cache in ASP.NET

Most of the times we need to store large amounts of data client side is by using the ViewState. It will only exist on the page you add it to though. So if you are jumping around from page to page it won't really work. In that case you really should be using Session or Application Cache depending on your scenario.


ViewState:  
 ViewState is one of the techniques that Asp.net provides in order to save the data for latter use. The important fact about the ViewState is that it can only save the values for page level access. It means that if I save something on page1.aspx using Viewstate I cannot access it on the page2.aspx using the same technique. For this reason ViewState is only used to save the values for the page level access which should be maintained after post backs.Whenever we write anything in the ViewState object a hidden field is created in the page. After the post back it will display the value of the dataset using the ViewState control.

So if you are doing something where you are always on the same page and just doing many PostBacks for things like paging or sorting then ViewState will work fine but do realize you will be passing large amounts of data back and forth to the server each time a PostBack is made.
Example Using ViewState:

// Set it
ViewState["dsViewEmp"] = dsEmployee;


// Get it
DataSet ds = ViewState[" dsViewEmp "] as DataSet;


Session and the Application Cache are accessed the same way. Just replace ViewState with the word Session or Cache.


What is Data Cache?
Data Cache is used to storing frequently used data in the Cache memory. It's much efficient to retrieve data from the data cache instead of database or other sources. We need use System.Web.Caching namespace. The scope of the data caching is within the application domain unlike "session". Every user can able to access this objects.


How data caching is work?
When client request to the server, server execute the stored procedure or function or select statements on the Sql Server database then it returns the response to the browser. If we run again same process will happen on the web server with sql server.
In the very first time retrieve the records from the sql server database and stored into the Cache memory.  After that records will retrieve from Cache memory (IIS). We can set expiration period time after expiration time over the caching again it will hit the sql server database and stored into the cache memory and next retrieve will happen on the data cache memory.


Advantages of Cookies
Following are main advantages of using cookies in web application:
It's very simple to use and implement.
We can avoid database hitting.
We can reduce network traffic.

How to create data cache? 
Cache["Employee"] = dsEmployee


We can create data caching use Cache Keyword. It's located in the System.Web.Caching namespace. It's just like assigning value to the variable


How to Read data from Data Cache?
Dataset dsEmployees = (Dataset) Cache ["Employee"]


This is very similar to assigning object to the Dataset.


Where does Data Cache are stored?
This is one of the interesting things to find out the Data Caching in your local drive. First of all, From "IE Internet Option ", delete Browsing History to clear Cache. 


How to remove a Data Cache? 
We can remove Data Cache manually.

//We need to specify the cache name


   Cache.Remove(String key);



Conclusion:
When it comes to choosing between ViewState and Caching it all comes down to what you are doing. ViewState is an ideal candidate if you are planning to save small values. Mostly values of server controls are saved in ViewState. If you plan to store large datasets, datatables or collections than data caching is an excellent candidate.


ReferenceLinks:
1. http://www.highoncoding.com/Articles/69_View_State_vs_Data_Caching.aspx
http://msdn.microsoft.com/en-us/library/z1hkazw7%28VS.80%29.aspx






05 May 2012

Using MID() to Cut Out a SubString

I have a filed that begins with numeirc characters and it ends with alpha character (like 0125461E). I want to alpha (E) part form the string and leave the remaining (0125461) field value.

we need to "cut" it out of our  IDNumber field.
Our example field is called {USERS. IDNumber}.
Now the way we cut strings out of other strings is with the MID() function. The MID function takes three parameters. The string on which to operate, where to start and the length of the string to return.

MID(String, Starting Character Position, Length of String to Return)

Supposing that {USERS. IDNumber } is going to return Justin Hill, we can see the result of various MID statements:
MID({USERS. IDNumber }, 8, 1) then we will get "E"
Also note that you may omit the final parameter (length) to return "the rest" of the string, like this:
MID({USERS. IDNumber  }, 8) 

Example:

//Declaring variable to display message...
Stringvar message;
if (MID({REP. IDNumber},  8 ,1)="E")
then message:="Employee" 

Pass value from main report to sub report

I am designing a report which includes sub report every thing is fine but i have to display the main report field value in sub report . To get the main report vale in to the sub report follow the bellow steps.
Step 1:
1. In main report create a formula, name it, edit it with the formula editor as follows:
Shared numbervar NAME := {Rep.Sno} 
Save formula.  Note that you should replace the name and type of variable and a formula with ones of your own
2. Now create a formula in your subreport, name it, edit it with the formula editor as follows:

Shared numbervar NAME;
NAME
3. Use formula created in step 2 in your report (drag drop in the report from formula fields.
Note that subreport is processed after the main report, so it's easier to pass values from main report to subreport.

01 May 2012

Display a serial number in RDLC report

I have developed a report in reportviewer using ASP.NET. I want to display serial number in report follow the below steps. In RDLC design drag and drop a text box from the toolbox and right click on it and select Expression as shown below.


An expression containing the RowNumber function, when used in a text box within a data region, displays the row number for each instance of the text box in which the expression appears. This function can be useful to number rows in a table.
Using RowNumber(Scope) function to display the row numbers. If scope is nothing then RowNumber(Nothing) provides the running count of rows in the outermost data region.

How to Change Date Format in .RDLC reports (MM/dd/yyyy)

In my Report Design i want to show date in the format of (MM/dd/yyyy). The column has the value in dd/MM/yyyy.  The output on the webform looks like this: 05/18/2012 to do this follow the below steps.
Step1: In RDLC design right click on the column/textbox and then it will open context menu as shown below then select the Expression option from the menu.
Step 2:When click on Expression then it will open a windows as shown below. Change the Expression statement as shown and then click on OK button.