Showing posts with label ASP.NET. Show all posts
Showing posts with label ASP.NET. Show all posts

Thursday, May 10, 2018

IIS 7.0 and above impotent error messages



200 - OK. The client request has succeeded.
400 - Bad request. The request could not be understood by the server due to malformed syntax. The             client should not repeat the request without modifications.
401 - Access denied.
403 - Forbidden.
404 - Not found.
500 - Internal server error.
501 - Header values specify a configuration that is not implemented.
502 - Web server received an invalid response while acting as a gateway or proxy.
503 - Service unavailable.


Friday, February 10, 2017

Suggestions or Auto populate values in textbox using JQuery and C#(SharePoint 2013)


I have done this on SharePoint application page which is deployed under layouts folder, this can be also used in .net applications.
below is images shows you populated suggestions that are saved in database


First fill the data inside a gridview/table with fields that you need to auto populate
this can be done based on your coding capabilities

once you do it hide the table so that anyone cannot see it using CSS or code in my case i did with CSS
.GridHide is my class for hiding gridview and below other two classed is used to autocomplete list

<style type="text/css">
.GrdHide {
            display:none;
        }
        ul.ui-autocomplete {
    list-style: none;
}
.ui-autocomplete {
    height: 200px;
    overflow-y: scroll;
    overflow-x: hidden;

}
</style>

Code in JQuery to populate table data inside textbox i did this for two textboxes for project name and project number you can repeat the same as many columns you want

function GetData() {
            var MYProjNumb = new Array();
            var MYProjName = new Array();

            var table = $("#ctl00_PlaceHolderMain_hiddenGrd tbody"); //my table ID

            table.find('tr').each(function (i) {
                var $tds = $(this).find('td'),
                    ProjectNumber = $tds.eq(0).text(),
                    ProjectName = $tds.eq(1).text(),


                //alert('Row ' + (i + 1) + ':\npNumber: ' + ProjectNumber
                //      + '\nPName: ' + ProjectName);
                MYProjNumb.push(ProjectNumber);
                MYProjName.push(ProjectName);

            });
            ProjNumber(MYProjNumb);
            ProjName(MYProjName);
        }
        function ProjNumber(list) {
            var PJlst = GetUnique(list);
            $("[id*=txtProjNum]").autocomplete({
                source: PJlst,
                select: function (event, ui) {
                }
            });
        }
        function ProjName(list) {
            var PNLst = GetUnique(list);
            $("[id*=txtProjectName]").autocomplete({
                source: PNLst,
                select: function (event, ui) {
                }
            });
        }

to display only unique values in auto suggestion box then use the below code

        function GetUnique(list)
        {
            var unique = list.filter(function (itm, i, a) {
                return i == a.indexOf(itm);
            });
            return unique;
        }

call the above GetData() method on load of page

    <script type="text/javascript">
        $(function () {
            GetData();
});
</script>

all set...now you have auto populate textboxes on your page
limit your table data to 50 so that page loads faster.

Wednesday, November 16, 2016

Checking selected value in all dropdowns using jquery


Below code works if you have multiple drop downs where you want to check the selected value in all drop downs  in the form and see if this value is selected already, if selected then will show an alert message and change the selected value of that particular drop down


Add the "OnChange" in dropdown events as this onchange="ChkCurrent(this);
where 'id' is current value dropdown
 function ChkCurrent(id) {   
            var ddlValues = new Array();
            $("[id*='ddlstsCurrM']").each(function (i) {
                if ($(this).val()== 1) {
                    ddlValues.push($(this).val());
                }

            });
            if (ddlValues.length > 1)
            {
                alert("This value has been already selected");
                var ddlid ="#"+id.id;
                $(ddlid).val('0');

            }
        }

Thursday, November 15, 2012

Web part page life cycle

Main Points are:

    protected override void OnInit(EventArgs e)
    protected override void OnLoad(EventArgs e)
    protected override void CreateChildControls()
    protected override void LoadViewState(object savedState) //Only at Postback
    protected override void OnPreRender(EventArgs e)
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    protected override void OnUnload(EventArgs e)
    public override void Dispose()



      Description:

      OnInit: This method handles initialization of the control.
      OnLoad: This event handles the Load event. This is also used for initialize the control but is not intended for loading data or other processing functionality.
      CreateChildControls: This is the most popular event in web part life cycle. This creates any child controls. So if you are adding any control to display then you have to write in this method.
      EnsureChildControls: This method ensures that CreateChildControls has executed. EnsureChildControls method must be called to prevent null reference exceptions.
      SaveViewState: View state of the web part saved.
      OnPreRender: This method handles or initiates tasks such as data loading that must complete before the control can render.
      Page.PreRenderComplete: The page fires the PreRenderComplete event after all controls have completed their OnPreRender methods.
      Render: This method is used to render everything.
      RenderContents: Renders the contents of the control only, inside of the outer tags and style properties.
      OnUnload: Performs the final cleanup.

      Friday, November 9, 2012

      Difference between CLR,CTS and CLS in .Net


      CLR....

      The Common Language Runtime (CLR) is the virtual machine component of Microsoft's .NET initiative. It is Microsoft's implementation of the Common Language Infrastructure (CLI) standard, which defines an execution environment for program code. The CLR runs a form of bytecode called the Common Intermediate Language (CIL, previously known as MSIL -- Microsoft Intermediate Language).
      Developers using the CLR write code in a language such as C# or VB.Net. At compile time, a .NET compiler converts such code into CIL code. At runtime, the CLR's just-in-time compiler converts the CIL code into code native to the operating system. Alternatively, the CIL code can be compiled to native code in a separate step prior to runtime. This speeds up all later runs of the software as the CIL-to-native compilation is no longer necessary.
      Although some other implementations of the Common Language Infrastructure run on non-Windows operating systems, Microsoft's implementation runs only on Microsoft Windows operating systems.

      The virtual machine aspect of the CLR allows programmers to ignore many details of the specific CPU that will execute the program. The CLR also provides other important services, including the following:

      * Memory management
      * Thread management
      * Exception handling
      * Garbage collection
      * Security

      CLS...

      To fully interact with other objects regardless of the language they were implemented in, objects must expose to callers only those features that are common to all the languages they must interoperate with. For this reason, the Common Language Specification (CLS), which is a set of basic language features needed by many applications, has been defined. The CLS rules define a subset of the common type system; that is, all the rules that apply to the common type system apply to the CLS, except where stricter rules are defined in the CLS. The CLS helps enhance and ensure language interoperability by defining a set of features that developers can rely on to be available in a wide variety of languages. The CLS also establishes requirements for CLS compliance; these help you determine whether your managed code conforms to the CLS and to what extent a given tool supports the development of managed code that uses CLS features.

      If your component uses only CLS features in the API that it exposes to other code (including derived classes), the component is guaranteed to be accessible from any programming language that supports the CLS. Components that adhere to the CLS rules and use only the features included in the CLS are said to be CLS-compliant components.

      Most of the members defined by types in the .NET Framework class library are CLS-compliant. However, some types in the class library have one or more members that are not CLS-compliant. These members enable support for language features that are not in the CLS. The types and members that are not CLS-compliant are identified as such in the reference documentation, and in all cases a CLS-compliant alternative is available. For more information about the types in the .NET Framework class library, see the .NET Framework Reference.

      The CLS was designed to be large enough to include the language constructs that are commonly needed by developers, yet small enough that most languages are able to support it. In addition, any language construct that makes it impossible to rapidly verify the type safety of code was excluded from the CLS so that all CLS-compliant languages can produce verifiable code if they choose to do so. For more information about verification of type safety, see JIT Compilation.

      The following table summarizes the features that are in the CLS and indicates whether the feature applies to both developers and compilers (All) or only compilers. It is intended to be informative, but not comprehensive. For details, see the specification for the Common Language Infrastructure, Partition I, which is located in the Tool Developers Guide directory installed with the Microsoft .NET Framework SDK.

      CTS.....

      The Common Type System (CTS) is a standard that specifies how Type definitions and specific values of Types are represented in computer memory. It is intended to allow programs written in different programming languages to easily share information. As used in programming languages, a Type can be described as a definition of a set of values (for example, "all integers between 0 and 10"), and the allowable operations on those values (for example, addition and subtraction).

      The specification for the CTS is contained in Ecma standard 335, "Common Language Infrastructure (CLI) Partitions I to VI." The CLI and the CTS were created by Microsoft, and the Microsoft .NET framework is an implementation of the standard.
       

      Difference between Web Site and Web application in ASP.NET


      • Development Wise Difference


      Web Site
      1. We can code one page in C# and one page in vb.net (Multiple programming languages allowed).
      2. We cannot call (access) public functions from one page to other page.
      3. Utility classes / functions must be placed in a special ASP.NET folder (the App_Code folder)
      4. Web Sites do not have a .csproj/.vbproj file that manages the project (the folder that contains the site becomes the project root).
      5. In the Web Site project, each file that you exclude is renamed with an exclude
      keyword in the filename.
      6. Explicit namespaces are not added to pages, controls, and classes by default, but you can add them manually.


      Web Application
      1. Only one programming language allowed per project (Need to decide on programming language when starting project).
      2. We can access public functions from one page to other page.
      3. Utility classes / function can be placed anywhere in the applications folder structure.
      4. Web Applications are treated like other .NET projects and are managed by a project file (.csproj or .vbproj) .
      5. One nice feature of the Web Application project is it's much easier to exclude files from the project view.
      6. Explicit namespaces are added to pages, controls, and classes by default.




      • Deployment wise difference


      Web Site
      1. It has its code in a special App_Code directory and it's compiled into several DLLs (assemblies) at runtime.
      2. No need to recompile the site before deployment.
      3. We need to deploy both .aspx file and code behind file.
      4. Small changes to the site do not require a full re-deployment. (We can upload the code file that was changed) 

      Web Application
      1. web application is precompiled into one single DLL.
      2. Site has to be pre-compiled before deployment .
      3. Deploy only .aspx page, but not associated code file (the pre-compiled dll will be uploaded) .
      4. Even small changes require a full re-compile of the entire site(i.e. if the code for a single page changes the whole site must be compiled) (It requires careful planning to ensure new bugs aren't introduced to the production site when uploading bug fixes or other changes.)




      sample format of .CSPROJ file in web application
      <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
          <ProjectView>ProjectFiles</ProjectView>
        </PropertyGroup>
        <ProjectExtensions>
          <VisualStudio>
            <FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
              <WebProjectProperties>
                <StartPageUrl>CheckboxListTest.aspx</StartPageUrl>
                <StartAction>SpecificPage</StartAction>
                <AspNetDebugging>True</AspNetDebugging>
                <NativeDebugging>False</NativeDebugging>
                <SQLDebugging>False</SQLDebugging>
                <PublishCopyOption>RunFiles</PublishCopyOption>
                <PublishTargetLocation>
                </PublishTargetLocation>
                <PublishDeleteAllFiles>False</PublishDeleteAllFiles>
                <PublishCopyAppData>True</PublishCopyAppData>
                <ExternalProgram>
                </ExternalProgram>
                <StartExternalURL>
                </StartExternalURL>
       

      SharePoint - Cannot convert a primitive value to the expected type 'Edm.Double'. See the inner exception for more details If y...

      Ad