Monday, 27 July 2015

Fixing HTTP Error 500.21 – Internal Server Error Handler “WebServiceHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler” in its module list on IIS.

I was recently developing some .net web applications at work and finally took the plunge of setting up a server to host them after I was happy that we had reached the point where they were usable applications.  So after setting up Server 2008 R2, I went ahead and enabled IIS with asp.net configuration enabled along with a host of other modules enabled to support what we were after. Gave the server a reboot and everything was up and ready to go.

Moved over to my development machine and instructed Visual Studio to publish an application to this newly setup web server, everything up until this point had worked perfectly, the web app published without any errors. So I opened up Internet explorer and low and behold error, page cannot be displayed. So I’m like maybe it’s a permissions thing, remoted into the web server and viewed it as a localhost and got Error 500.21 – Internal Server Error  Handler “WebServiceHandlerFactory-Integrated” has a bad module “ManagedPipelineHandler”.  I had gone ahead and configured an application pool for the web apps we were going to use, and everything seemed OK.  I then remembered something, in the good old IIS 6 days you had to run a .net registration program to notify IIS you had it installed and register the handlers for .net, but thinking to myself this is now 2008 R2, come on, it couldn’t be that.

I opened up an elevated command prompt window and navigated to C:\Windows\Microsoft.NET\Framework\v4.0.30319 and ran aspnet_regiis.exe -i causing asp.net to register itself with IIS and enable the handlers required to run .net pages.


After running this command I rebooted IIS and bang the web application started working.  An easy fix but a pity that it couldn’t have run automatically when I insist on installing asp.net under the IIS configuration.

Tuesday, 5 May 2015

Display Data using 2 Dropdownlist in 1 GridView.


Below is the code for Displaying the DropDownLists.





<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="bankname"            DataValueField="bankname"></asp:DropDownList>

<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SqlDataSource2" DataTextField="scheme" DataValueField="scheme">
</asp:DropDownList>        

<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:tracking %>" SelectCommand="SELECT * FROM [scheme]"></asp:SqlDataSource>
 

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:tracking %>" SelectCommand="SELECT * FROM [bank]"></asp:SqlDataSource>
     
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Search" class="btn_green" />



<div class="sh" style="width: 10px;">
 

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource3" Visible="False" ForeColor="#333333"  CssClass="table table-bordered" onselectedindexchanged="GridView_SelectedIndexChanged">

<AlternatingRowStyle BackColor="White" />
 

<Columns>
 

<asp:CommandField ShowSelectButton="True" />
 

<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" InsertVisible="False" ReadOnly="True" />

<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />

<asp:BoundField DataField="loanamount" HeaderText="loanamount" SortExpression="loanamount" />

<asp:BoundField DataField="branch" HeaderText="branch" SortExpression="branch" />
 

<asp:BoundField DataField="officename" HeaderText="officename" SortExpression="officename" />
 

<asp:BoundField DataField="schemename" HeaderText="schemename" SortExpression="schemename" />

<asp:BoundField DataField="reciptoffdate" HeaderText="reciptoffdate" SortExpression="reciptoffdate" DataFormatString="{0:dd/MM/yyyy}" />
                

</Columns>
 

<EditRowStyle BackColor="#2461BF" />
 

<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                

<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

<RowStyle BackColor="#EFF3FB" />
 

<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />

<SortedAscendingCellStyle BackColor="#F5F7FB" />

<SortedAscendingHeaderStyle BackColor="#6D95E1" />

<SortedDescendingCellStyle BackColor="#E9EBEF" />               

<SortedDescendingHeaderStyle BackColor="#4870BE" />
 

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:tracking %>" SelectCommand="SELECT [id], [name], [loanamount], [branch], [officename], [schemename], [reciptoffdate] FROM [transaction] WHERE (([branch] = @branch) AND ([schemename] = @schemename))">
<SelectParameters>
                    

<asp:ControlParameter ControlID="DropDownList1" Name="branch" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="DropDownList2" Name="schemename" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="Label1" runat="server" Text="" Visible="false"></asp:Label>




Now We will see the code behind it:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView_SelectedIndexChanged(Object sender, EventArgs e)
    {
      


string apid = GridView1.SelectedRow.Cells[1].Text;
       Session["appno"] = apid;
       Response.Redirect("print.aspx");
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

      
        string query = "select * from [transaction] where  schemename='" + DropDownList2.SelectedItem.Text.ToString() + "'and branch='" + DropDownList1.SelectedItem.Text.ToString() + " '  ";
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["tracking"].ConnectionString);
            SqlCommand cmd = new SqlCommand(query, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
           con.Open();
          
            sqlReader=cmd.ExecuteReader();
            if (sqlReader.Read())
            {
                Label1.Visible = false;
                GridView1.Visible = true;
            }
            else
            {
                Label1.Visible = true;
                GridView1.Visible = false;
                Label1.Text = "error";
            }
        con.Close();
       
    }

    public SqlDataReader sqlReader { get; set; }
}
 

This is the grid view when we click on the search button And when we click on the select in the Table We get redirected to an other page which displays all its details.

Tuesday, 24 March 2015

How to change the modes of formview in asp.net C#?

The Edit mode provides us the updation methods:-

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        FormView1.ChangeMode(FormViewMode.Edit);
    }

The Insert mode provides us the addition of new record:-

    protected void butAddNew_Click(object sender, EventArgs e)
    {
        FormView1.ChangeMode(FormViewMode.Insert);
    }