|
-
Powered by
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dynamically Load User controls
<<<<<<<<<—-Back to article
Table SQL Code to Create Feedback table
CREATE TABLE [aspfree].[articleFeedback]
(
[id] [int] IDENTITY (1, 1) NOT NULL ,
[articleLink] [varchar] (255) NULL ,
[dateSubmitted] [datetime] NULL ,
[articleRating] [int] NULL ,
[articleComments] [varchar] (500) NULL
) ON [PRIMARY]
GO
ALTER TABLE [aspfree].[articleFeedback] WITH NOCHECK ADD
CONSTRAINT [DF_articleFeedback_dateSubmitted] DEFAULT (getdate()) FOR [dateSubmitted],
CONSTRAINT [PK_articleFeedback] PRIMARY KEY CLUSTERED
(
[id]
) ON [PRIMARY]
GOStored Procedure to Insert Data
CREATE PROCEDURE spInsertFeedback
(
@articleLink varchar(255),
@articleRating int,
@articleComments varchar(500)
)
AS
Insert into articleFeedback(articleLink, articleRating, articleComments)
values(@articleLink, @articleRating, @articleComments)
GO |
uc_good.aspx, uc_good.ascx code
uc_good.aspx Web Page
<%@ Page language="VB" Trace="True" %>
<%@ Register TagPrefix="Tag" TagName="Name" Src="uc_good.ascx" %>
<html>
<head></head>
<body>
<Tag:Name ShowFeedBack="Yes" runat="server" />
</body>
</html>
uc_good.ascx User Control<!–Will Show Feedback form if
property set to yes–>
<script language="VB" runat="server">
‘Define ShowFeedback property
Public ShowFeedBack as string
Protected Sub Page_Load(Source as Object, E as EventArgs)
If ShowFeedBack = "Yes" Then
Dim uc As Control = Page.LoadControl("uc_form.ascx")
myPlaceHolder.Controls.Add(uc)
End If
End Sub
</script>
<asp:PlaceHolder runat="server" id="myPlaceHolder" /> |
uc_bad.aspx, uc_bad.ascx code
uc_bad.aspx Web Page
<%@ Page language="VB" Trace="True" %>
<%@ Register TagPrefix="Tag" TagName="Name" Src="uc_good.ascx" %>
<html>
<head></head>
<body>
<Tag:Name ShowFeedBack="Yes" runat="server" />
</body>
</html>uc_bad.ascx User Control
<script language="vb" runat="server">
Public ShowFeedBack as String
</script>
<%
If ShowFeedBack = "Yes" Then
%>
<%@ Register TagPrefix="Tag" TagName="Feedback" Src="feedback.ascx" %>
<Tag:Feedback runat="server" />
<%
End If
%> |
Article Feedback form
<%@ Control Language="VB" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
BindGrid
End Sub
Sub Message_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
dim articleLink as string = Request.Path.ToString()
dim articleRating as string = RadioButtonList1.SelectedItem.Text
dim strarticleComments as string = Request.Form("txtarticleComments")
dim SQL as string = "Exec spInsertFeedback ‘" & articleLink & "’, ‘" &
articleRating & "’, ‘" & strarticleComments & "’"
ExecuteSQL(SQL)
BindGrid()
End If
End Sub
‘This Generate function executes Inserts, updates.
Sub ExecuteSQL(SQL as string)
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("DSN"))
dim cmd as SqlCommand = new SqlCommand(SQL, myConnection)
MyConnection.Open()
cmd.ExecuteNonQuery()
MyConnection.Close()
End Sub
Sub MyDataGrid_Page(sender As Object, e As DataGridPageChangedEventArgs)
dim startindex as integer
startIndex = MyDataGrid.CurrentPageIndex * MyDataGrid.PageSize
MyDataGrid.CurrentPageIndex = e.NewPageIndex
BindGrid
End Sub
Sub BindGrid()
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("DSN"))
dim ds as DataSet = new DataSet()
dim sSql as string = "select * from articleFeedback where articleLink=’" &
request.Path & "’ order by dateSubmitted DESC"
dim adapter as SqlDataAdapter = new SqlDataAdapter(sSql, myConnection)
adapter.Fill(ds,"articleFeedback")
MyDataGrid.DataSource=ds.Tables("articleFeedback").DefaultView
MyDataGrid.DataBind()
End Sub
Sub PagerButtonClick(sender As Object, e As EventArgs)
‘used by external paging UI
Dim arg As string = sender.CommandArgument
Select arg
Case "next":
If (MyDataGrid.CurrentPageIndex < (MyDataGrid.PageCount – 1)) Then
MyDataGrid.CurrentPageIndex += 1
End If
Case "prev":
If (MyDataGrid.CurrentPageIndex > 0) Then
MyDataGrid.CurrentPageIndex -= 1
End If
Case "last":
MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount – 1)
Case Else:
‘page number
MyDataGrid.CurrentPageIndex = System.Convert.ToInt32(arg)
End Select
BindGrid
End Sub
</script>
<center>
<form method="post" name="frmFeedBack" runat="server">
<table border="0" width="50%">
<tr>
<td colspan="3" align="center"><asp:Label id="lblRateArticle" tooltip="Enter
Rating" Font-Name="Arial" Forecolor="#000000" Text="Rate this Article" runat="server"/></td>
</tr>
<tr>
<td>Poor!</td>
<td align="center">
<ASP:RadioButtonList id=RadioButtonList1 RepeatDirection="Horizontal" runat=server>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem Selected="True">3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</ASP:RadioButtonList>
</td>
<td>Good!</td>
</tr>
<tr>
<td colspan="3" align="center"><asp:Label id="lblComments" tooltip="Enter
Rating" Font-Name="Arial" Forecolor="#000000" Font-size="8pt"
Text="Comments:(255 max please)" runat="server"/></td>
</tr>
<tr>
<td colspan="3" align="center"><textarea id="txtarticleComments" name="txtarticleComments"
cols="30" rows="4"></textarea></td>
</tr>
<tr>
<td colspan="3" align="center"><asp:Button id="btnSubmit" OnClick="Message_Click"
text="Submit Message" runat="server"/></td>
</tr>
</table>
<br />
<br />
<ASP:DataGrid id="MyDataGrid" runat="server"
AllowPaging="True"
PageSize="5"
PageCount="1"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Right"
OnPageIndexChanged="MyDataGrid_Page"
BorderColor="black"
BorderWidth="1"
GridLines="Both"
CellPadding="3"
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
Align="center"
HeaderStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
AutoGenerateColumns="False"
>
<Columns>
<asp:BoundColumn HeaderText="Date Submitted" DataField="DateSubmitted" />
<asp:BoundColumn HeaderText="articleRating" DataField="articleRating"/>
<asp:BoundColumn HeaderText="articleComments" DataField="articleComments"/>
</Columns>
</asp:datagrid>
<asp:LinkButton id="btnFirst" runat="server"
Text="First page"
CommandArgument="0"
ForeColor="navy"
Font-Name="verdana" Font-size="8pt"
OnClick="PagerButtonClick"
/>
<asp:LinkButton id="btnPrev" runat="server"
Text="<<<"
CommandArgument="prev"
ForeColor="navy"
Font-Name="verdana" Font-size="8pt"
OnClick="PagerButtonClick"
/>
<asp:LinkButton id="btnNext" runat="server"
Text=">>>"
CommandArgument="next"
ForeColor="navy"
Font-Name="verdana" Font-size="8pt"
OnClick="PagerButtonClick"
/>
<asp:LinkButton id="btnLast" runat="server"
Text="Last page"
CommandArgument="last"
ForeColor="navy"
Font-Name="verdana" Font-size="8pt"
OnClick="PagerButtonClick"
/>
</form>
</center> |
|
|
tio |