Friday 30 June 2017

Tab in asp.net

Tab in asp.net

<asp:Menu ID="Menu1" Orientation="Horizontal" runat="server" OnMenuItemClick="Menu1_MenuItemClick">
            <Items>
                <asp:MenuItem Text="first tab" Value="0" Selected="true"></asp:MenuItem>
                <asp:MenuItem Text="second tab" Value="1"></asp:MenuItem>
            </Items>
        </asp:Menu>
        <asp:MultiView ID="MultiView1" ActiveViewIndex="0" runat="server">
            <asp:View ID="View1" runat="server">
                <div style="border: 1px solid black; width: 10%; height: 100px">
                    hello...
                </div>
            </asp:View>
            <asp:View ID="View2" runat="server">
                <div style="border: 1px solid black; width: 10%; height: 100px">
                    hye....
                </div>
            </asp:View>
</asp:MultiView>



protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {
            int index = Int32.Parse(e.Item.Value);
            MultiView1.ActiveViewIndex = index;
        }

Print page using Javascript in asp.net

Print the page content on button click using javascript in asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="demo.aspx.cs" Inherits="Demosolution.demo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function Panel() {
            debugger
            var panel = document.getElementById("<%=pnlContents.ClientID %>");
            var printWindow = window.open('', '', 'height=400,width=800');
            printWindow.document.write(panel.innerHTML);
            setTimeout(function () {
                printWindow.print();
            }, 500);
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="Print" runat="server" Text="Print " OnClientClick="return Panel();" />
        <asp:Panel ID="pnlContents" Visible="true" Style="visibility: hidden" runat="server">
            <div id="x" class="container" style="width: 90%; border: solid">
                <p>Test msg</p>
                <p style="color: red;">Test msg</p>
                <p style="color: blue;">Test msg</p>
                <p style="font-size: 36px;">Test msg</p>
            </div>
        </asp:Panel>
    </form>
</body>
</html>



Print the popup window content on button click using javascript in asp.net


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="demo.aspx.cs" Inherits="Demosolution.demo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function Panel() {
            debugger
            var panel = document.getElementById("<%=pnlContents.ClientID %>");
            // panel.style.visibility = "visible";
            var printWindow = window.open('', '', 'height=400,width=800');
            printWindow.document.write(panel.innerHTML);
            return false;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="Print" runat="server" Text="Click to open window" OnClientClick="return Panel();" />
        <asp:Panel ID="pnlContents" Style="visibility: hidden" runat="server">
            <div id="x" class="container" style="width: 90%; border: solid" runat="server">
                <p>Test msg</p>
                <p style="color: red;">Test msg</p>
                <p style="color: blue;">Test msg</p>
                <p style="font-size: 36px;">Test msg</p>
            </div>
            <asp:Button ID="Button1" runat="server" Text="Print"
            OnClientClick="javascript:NewWindow=window.open('', '', 'height=240,width=800');NewWindow.document.write(x.innerHTML);NewWindow.print()" />
        </asp:Panel>
    </form>
</body>
</html>