Open page when badge notification icon is Clicked in ASP.Net

makumbi
 
on Dec 05, 2022 05:17 AM
570 Views

I am trying opening a webpage homework page, but when i go to properties, i do not see the on click options

please help

<div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
    <div class="container">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <table class="auto-style1">
        <tr>
            <td class="auto-style5">
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <button class="btn btn-default btn-lg btn-link" style="font-size:36px; width: 74px; height: 15px;">
                           <asp:Label ID="Counterd" runat="server" Text="good" class="badge badge-notify" Height="16px" Width="28px">3</asp:Label>
                            <span class="glyphicon glyphicon-comment" style="left: -65px; top: -5px; width: 9px"></span>
                        </button>
                        <br />
                        <br />
                        Home Work<br />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
    </div>    
        <table cellpadding="2" class="auto-style1">
            <tr>
                <td class="auto-style3">Student Name</td>
                <td class="auto-style3">
                    <asp:Label ID="StudentName" runat="server" Text="Label"></asp:Label>
                </td>
                <td class="auto-style3">Account</td>
                <td class="auto-style3">
                    <asp:Label ID="Account" runat="server" Text="Label"></asp:Label>
                </td>
                <td class="auto-style3">Class</td>
                <td class="auto-style3">
                    <asp:Label ID="Classr" runat="server" Text="Label"></asp:Label>
                </td>
                <td class="auto-style3">
                    <asp:Label ID="Stream" runat="server" Text="Label"></asp:Label>
                </td>
                <td class="auto-style3">Subject</td>
                <td class="auto-style3">
                            <asp:DropDownList ID="SubjectData" runat="server" Height="23px" Width="215px">
                            </asp:DropDownList>
                        </td>
                <td class="auto-style3">
                    <asp:Button ID="Button1" runat="server" Text="SignOut" />
                </td>
            </tr>
            <tr>
                <td class="auto-style10" colspan="10">
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <asp:GridView ID="StudentGrid" runat="server" AutoGenerateColumns="False" Width="1248px" CssClass="auto-style2">
                                <Columns>
                                    <asp:BoundField DataField="Topic" HeaderText="Topic" />
                                    <asp:BoundField DataField="Subject" HeaderText="Subject" />
                                    <asp:BoundField DataField="Dates" HeaderText="Date Uploaded" />
                                    <asp:BoundField DataField="Name" HeaderText="File Name" />
                                    <asp:TemplateField ItemStyle-HorizontalAlign="Center">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lnkView" runat="server" CommandArgument='<%# Eval("Id") %>' OnClick="View" Text="View"></asp:LinkButton>
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Center" />
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                        </ContentTemplate>
                          <Triggers>
                              <asp:PostBackTrigger ControlID="StudentGrid" />
                          </Triggers>
                    </asp:UpdatePanel>
                </td>
            </tr>
            <tr>
                <td class="auto-style2">&nbsp;</td>
                <td class="auto-style2">&nbsp;</td>
                <td class="auto-style2">&nbsp;</td>
                <td class="auto-style2">&nbsp;</td>
                <td class="auto-style2">&nbsp;</td>
                <td colspan="5" class="auto-style2">&nbsp;</td>
            </tr>
        </table>    
</div>

 

Public Class StudentWork
    Inherits System.Web.UI.Page
    Dim constr As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            Using con As New SqlConnection(constr)
                Using cmd As New SqlCommand("SELECT subkey, Subject FROM Subjects")
                    cmd.CommandType = CommandType.Text
                    cmd.Connection = con
                    con.Open()
                    SubjectData.DataSource = cmd.ExecuteReader()
                    SubjectData.DataTextField = "Subject"
                    SubjectData.DataValueField = "subkey"
                    SubjectData.DataBind()
                    con.Close()
                End Using
            End Using
            SubjectData.Items.Insert(0, New ListItem("--Select Subject--", "0"))

            Account.Text = Session("account").ToString
            StudentName.Text = Session("Name").ToString
            Classr.Text = Session("Class").ToString
            Stream.Text = Session("Stream").ToString
            BindGrid()
        End If
    End Sub

    Private Sub BindGrid()
        Dim constr As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand()
                cmd.Parameters.AddWithValue("@c", Classr.Text)
                cmd.CommandText = "SELECT Id, Name,Topic,Class,Stream,Subject,Dates FROM tblFiles2 where class=@c"
                cmd.Connection = con
                con.Open()
                StudentGrid.DataSource = cmd.ExecuteReader()
                StudentGrid.DataBind()
                con.Close()
            End Using
        End Using
    End Sub

    Protected Sub View(sender As Object, e As EventArgs)
        Dim id As Integer = Integer.Parse(TryCast(sender, LinkButton).CommandArgument)
        Try
            ProcessRequest2(id, HttpContext.Current)
        Catch ex As SystemException

        End Try
    End Sub
    Public Sub ProcessRequest2(id As Integer, context As HttpContext)
        Dim bytes As Byte()
        Dim fileextension As String
        Dim constr As String = ConfigurationManager.ConnectionStrings("SLISConnectionString").ConnectionString
        Using con As New SqlConnection(constr)
            Using cmd As New SqlCommand()
                cmd.CommandType = CommandType.Text
                cmd.Connection = con
                con.Open()
                cmd.Parameters.AddWithValue("@FileID", id)
                cmd.CommandText = "SELECT Name, Data, ContentType FROM tblFiles2 WHERE Id=@FileID"
                Using sdr2 As SqlDataReader = cmd.ExecuteReader()
                    sdr2.Read()
                    bytes = DirectCast(sdr2("Data"), Byte())
                    fileextension = sdr2("Name").ToString()
                End Using
                con.Close()
            End Using
        End Using
        context.Response.Buffer = True
        context.Response.Charset = ""
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
        If fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "pdf" Then
            context.Response.Buffer = True
            context.Response.Charset = ""
            context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
            context.Response.ContentType = "application/pdf"
            context.Response.BinaryWrite(bytes)
            context.Response.Flush()
            context.Response.[End]()
        ElseIf fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "doc" OrElse fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "docx" Then
            File.WriteAllBytes(Server.MapPath(Convert.ToString("~/Temp/") & fileextension), bytes)
            WriteWordFile(Server.MapPath(Convert.ToString("~/Temp/") & fileextension))
        End If
    End Sub
    Private Sub WriteWordFile(filePath As Object)
        Dim missingType As Object = Type.Missing
        Dim [readOnly] As Object = True
        Dim isVisible As Object = False
        Dim documentFormat As Object = 8
        Dim randomName As String = DateTime.Now.Ticks.ToString()
        Dim htmlFilePath As Object = (Server.MapPath("~/Temp/") & randomName) + ".htm"
        Dim directoryPath As String = (Server.MapPath("~/Temp/") & randomName) + "_files"
        Dim applicationclass As New Application
        applicationclass.Documents.Open(filePath, [readOnly], missingType, missingType, missingType, missingType,
         missingType, missingType, missingType, missingType, isVisible, missingType,
         missingType, missingType, missingType, missingType)
        applicationclass.Visible = False
        Dim document As Document = applicationclass.ActiveDocument
        document.SaveAs(htmlFilePath, documentFormat, missingType, missingType, missingType, missingType,
         missingType, missingType, missingType, missingType, missingType, missingType,
         missingType, missingType, missingType, missingType)
        document.Close(missingType, missingType, missingType)
        Dim bytes As Byte()
        Using fs As New FileStream(htmlFilePath.ToString(), FileMode.Open, FileAccess.Read)
            Dim reader As New BinaryReader(fs)
            bytes = reader.ReadBytes(CInt(fs.Length))
            fs.Close()
        End Using
        Response.BinaryWrite(bytes)
        Response.Flush()
        File.Delete(htmlFilePath.ToString())
        For Each file_1 As String In Directory.GetFiles(directoryPath)
            File.Delete(file_1)
        Next
        Directory.Delete(directoryPath)
        If File.Exists(filePath.ToString()) Then
            File.Delete(filePath.ToString())
        End If
        Response.[End]()
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Response.Redirect("~/Logindata.aspx")
    End Sub
End Class

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
PrinceG
 
on Dec 05, 2022 11:42 PM

Hi makumbi,

Please refer below sample.

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<div class="container">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <table class="auto-style1">
        <tr>
            <td class="auto-style5">
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <button class="btn btn-default btn-lg btn-link" style="font-size: 36px; width: 74px; height: 15px;">
                            <asp:LinkButton ID="lnkCountered" runat="server" Text="Good" class="badge badge-notify" Height="19px" Width="28px" OnClick="Button1_Click">3</asp:LinkButton>
                            <span class="glyphicon glyphicon-comment" style="left: -65px; top: -5px; width: 9px"></span>
                        </button>
                        <br />
                        <br />
                        Home Work<br />
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
    </table>
</div>

<table cellpadding="2" class="auto-style1">
    <tr>
        <td class="auto-style3">Student Name</td>
        <td class="auto-style3">
            <asp:Label ID="StudentName" runat="server" Text="Label"></asp:Label>
        </td>
        <td class="auto-style3">Account</td>
        <td class="auto-style3">
            <asp:Label ID="Account" runat="server" Text="Label"></asp:Label>
        </td>
        <td class="auto-style3">Class</td>
        <td class="auto-style3">
            <asp:Label ID="Classr" runat="server" Text="Label"></asp:Label>
        </td>
        <td class="auto-style3">
            <asp:Label ID="Stream" runat="server" Text="Label"></asp:Label>
        </td>
        <td class="auto-style3">Subject</td>
        <td class="auto-style3">
            <asp:DropDownList ID="SubjectData" runat="server" Height="23px" Width="215px">
            </asp:DropDownList>
        </td>
        <td class="auto-style3">
            <asp:Button ID="Button1" runat="server" Text="SignOut" />
        </td>
    </tr>
    <tr>
        <td class="auto-style10" colspan="10">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:GridView ID="StudentGrid" runat="server" AutoGenerateColumns="False" Width="1248px" CssClass="auto-style2">
                        <Columns>
                            <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />
                            <asp:BoundField DataField="ContactName" HeaderText="ContactName" />
                            <asp:BoundField DataField="City" HeaderText="City" />
                            <asp:BoundField DataField="Country" HeaderText="Country" />
                            <asp:TemplateField ItemStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkView" runat="server" CommandArgument='<%# Eval("CustomerID") %>' OnClick="View" Text="View"></asp:LinkButton>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID="StudentGrid" />
                </Triggers>
            </asp:UpdatePanel>
        </td>
    </tr>
    <tr>
        <td class="auto-style2">&nbsp;</td>
        <td class="auto-style2">&nbsp;</td>
        <td class="auto-style2">&nbsp;</td>
        <td class="auto-style2">&nbsp;</td>
        <td class="auto-style2">&nbsp;</td>
        <td colspan="5" class="auto-style2">&nbsp;</td>
    </tr>
</table>

Namespaces

C#

using System.IO;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

VB.Net

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient

Code

C#

private string constr = "Data Source=.\\SQL2019;DataBase=northwind;UID=sa;PWD=PASSWORD";
protected void Page_Load(object sender, System.EventArgs e)
{
    if (!this.IsPostBack)
    {
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT ProductID, ProductName FROM Products"))
            {
                cmd.CommandType = CommandType.Text;
                cmd.Connection = con;
                con.Open();
                SubjectData.DataSource = cmd.ExecuteReader();
                SubjectData.DataTextField = "ProductName";
                SubjectData.DataValueField = "ProductID";
                SubjectData.DataBind();
                con.Close();
            }
        }
        SubjectData.Items.Insert(0, new ListItem("--Select Subject--", "0"));
        BindGrid();
    }
}

private void BindGrid()
{
    string constr = "Data Source=.\\SQL2019;DataBase=northwind;UID=sa;PWD=PASSWORD";
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.Parameters.AddWithValue("@CustomerID", Classr.Text);
            cmd.CommandText = "SELECT CustomerID,CompanyName,ContactName,City,Country FROM Customers where CustomerID=@CustomerID";
            cmd.Connection = con;
            con.Open();
            StudentGrid.DataSource = cmd.ExecuteReader();
            StudentGrid.DataBind();
            con.Close();
        }
    }
}

protected void View(object sender, EventArgs e)
{
}

public void ProcessRequest2(int id, HttpContext context)
{
    byte[] bytes;
    string fileextension;
    string constr = "Data Source=.\\SQL2019;DataBase=northwind;UID=sa;PWD=PASSWORD";
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            con.Open();
            cmd.Parameters.AddWithValue("@Id", id);
            cmd.CommandText = "SELECT Name, Data, ContentType FROM tblFiles WHERE Id=@Id";
            using (SqlDataReader sdr2 = cmd.ExecuteReader())
            {
                sdr2.Read();
                bytes = (byte[])sdr2["Data"];
                fileextension = sdr2["Name"].ToString();
            }
            con.Close();
        }
    }
    context.Response.Buffer = true;
    context.Response.Charset = "";
    context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    if (fileextension.Substring(fileextension.IndexOf('.') + 1).ToLower() == "pdf")
    {
        context.Response.Buffer = true;
        context.Response.Charset = "";
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        context.Response.ContentType = "application/pdf";
        context.Response.BinaryWrite(bytes);
        context.Response.Flush();
        context.Response.End();
    }
    else if (fileextension.Substring(fileextension.IndexOf('.') + 1).ToLower() == "doc" || fileextension.Substring(fileextension.IndexOf('.') + 1).ToLower() == "docx")
    {
        File.WriteAllBytes(Server.MapPath(Convert.ToString("~/Temp/") + fileextension), bytes);
        WriteWordFile(Server.MapPath(Convert.ToString("~/Temp/") + fileextension));
    }
}
private void WriteWordFile(object filePath)
{
}

protected void Button1_Click(object sender, EventArgs e)
{
    ScriptManager.RegisterStartupScript(this,this.GetType(), "alert", "alert('You are get to the next Page')", true);
}

VB.Net

Private constr As String = "Data Source=.\SQL2019;DataBase=northwind;UID=sa;PWD=PASSWORD"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Using con As SqlConnection = New SqlConnection(constr)
            Using cmd As SqlCommand = New SqlCommand("SELECT ProductID, ProductName FROM Products")
                cmd.CommandType = CommandType.Text
                cmd.Connection = con
                con.Open()
                SubjectData.DataSource = cmd.ExecuteReader()
                SubjectData.DataTextField = "ProductName"
                SubjectData.DataValueField = "ProductID"
                SubjectData.DataBind()
                con.Close()
            End Using
        End Using

        SubjectData.Items.Insert(0, New ListItem("--Select Subject--", "0"))
        Account.Text = Session("CompanyName").ToString()
        StudentName.Text = Session("ContactName").ToString()
        Classr.Text = Session("City").ToString()
        Stream.Text = Session("Country").ToString()
        BindGrid()
    End If
End Sub

Private Sub BindGrid()
    Dim constr As String = "Data Source=.\SQL2019;DataBase=northwind;UID=sa;PWD=PASSWORD"
    Using con As SqlConnection = New SqlConnection(constr)
        Using cmd As SqlCommand = New SqlCommand()
            cmd.Parameters.AddWithValue("@CustomerID", Classr.Text)
            cmd.CommandText = "SELECT CustomerID,CompanyName,ContactName,City,Country FROM Customers where CustomerID=@CustomerID"
            cmd.Connection = con
            con.Open()
            StudentGrid.DataSource = cmd.ExecuteReader()
            StudentGrid.DataBind()
            con.Close()
        End Using
    End Using
End Sub

Protected Sub View(ByVal sender As Object, ByVal e As EventArgs)

End Sub

Public Sub ProcessRequest2(ByVal id As Integer, ByVal context As HttpContext)
    Dim bytes As Byte()
    Dim fileextension As String
    Dim constr As String = "Data Source=.\SQL2019;DataBase=northwind;UID=sa;PWD=PASSWORD"
    Using con As SqlConnection = New SqlConnection(constr)
        Using cmd As SqlCommand = New SqlCommand()
            cmd.CommandType = CommandType.Text
            cmd.Connection = con
            con.Open()
            cmd.Parameters.AddWithValue("@Id", id)
            cmd.CommandText = "SELECT Name, Data, ContentType FROM tblFiles WHERE Id=@Id"
            Using sdr2 As SqlDataReader = cmd.ExecuteReader()
                sdr2.Read()
                bytes = CType(sdr2("Data"), Byte())
                fileextension = sdr2("Name").ToString()
            End Using
            con.Close()
        End Using
    End Using

    context.Response.Buffer = True
    context.Response.Charset = ""
    context.Response.Cache.SetCacheability(HttpCacheability.NoCache)

    If fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "pdf" Then
        context.Response.Buffer = True
        context.Response.Charset = ""
        context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
        context.Response.ContentType = "application/pdf"
        context.Response.BinaryWrite(bytes)
        context.Response.Flush()
        context.Response.[End]()
    ElseIf fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "doc" OrElse fileextension.Substring(fileextension.IndexOf("."c) + 1).ToLower() = "docx" Then
        File.WriteAllBytes(Server.MapPath(Convert.ToString("~/Temp/") & fileextension), bytes)
        WriteWordFile(Server.MapPath(Convert.ToString("~/Temp/") & fileextension))
    End If
End Sub

Private Sub WriteWordFile(ByVal filePath As Object)
End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alert", "alert('You are get to the next Page')", True)
End Sub

Screenshot