rosiec 0 Newbie Poster

I have a submit button that inserts user entered data into a database. It was working perfectly fine until I migrated the project to the host server. The database query is still functional and displaying my data in the GridView (I checked by manually inserting some data into the database on the host server), but data is not being inserted for whatever reason. It's an access database and I am connecting to it using the Visual Studio AccessDataSource.

Here is my code:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="jotest.aspx.vb" Inherits="jotest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script language="javascript" type="text/javascript">
<!--
            function imposeMaxLength(Object, MaxLen) {
                return (Object.value.length <= MaxLen);
            }
-->
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/login.mdb" 
DeleteCommand="DELETE FROM tblComments WHERE ID = @ID" 
InsertCommand="INSERT INTO tblComments(comment, commentor_name, comment_date) VALUES (@comment, @commentor_name, @comment_date)" 
 SelectCommand="SELECT ID, commentor_name, comment, comment_date FROM tblComments">
<InsertParameters>
<asp:Parameter Name="commentor_name" />
<asp:Parameter Name="comment" />
<asp:Parameter Name="comment_date" />
<asp:Parameter Name="ID" />
</InsertParameters>
<DeleteParameters>
<asp:Parameter Name="ID" />
</DeleteParameters>
</asp:AccessDataSource>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="position: absolute; top: 50px; left: 600px;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="AccessDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="comment" HeaderText="Name" SortExpression="comment" ItemStyle-Width="80px" />
<asp:BoundField DataField="commentor_name" HeaderText="Comment" SortExpression="commentor_name" ItemStyle-Width="300px" />
<asp:BoundField DataField="comment_date" HeaderText="Date" SortExpression="date" ItemStyle-Width="175px" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle …
rosiec 0 Newbie Poster

Thanks. I was messing around with it for a bit and managed to get to that. Unfortunately, I now have a new error:

Compiler Error Message: BC30108: 'HiddenField' is a type and cannot be used as an expression.

Also, in my code editor, "HiddenField", "hidDate" and "FormView" are all underlined with blue squiggles. Putting Parentheses around HiddenField and hidDate got rid of those (so it read (HiddenField hidDate = (HiddenField)FormView1...), but now it says my first parentheses is a syntax error.

I'm kinda in over my head, but I need to complete this project, so all your help is much appreciated.

rosiec 0 Newbie Poster

This looks like it is supposed to be VB.Net, if so why do you have ";" at the end of the lines?

The code was originally C# and I'm trying to convert it to VB. Like I said, not a ton of experience with either. I took the semi-colons out, but that doesn't fix my identifier problem.

rosiec 0 Newbie Poster

I have some code-behind and I am running in to an error. I am still very new to ASP.NET so I am having difficulty figuring out the "identifier expected" error.

Here is my code:

Partial Class Comments2
    Inherits System.Web.UI.Page

    Protected Sub 
    Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    HiddenField hidDate = (HiddenField)FormView1.FindControl("hidTimeDate");
	hidDate.Value = DateTime.Now.ToString();

    End Sub
End Class

Thank you for any help!

rosiec 0 Newbie Poster

Sorry if this is a dumb question, but I'm a newbie. Is the code you gave me in your last response the code-behind for the submit button?

Thank you for all your help.

rosiec 0 Newbie Poster

I take users don't have to log in to your site or you wouldn't need to protect the comment box, normal log ins could take care of that.
But all you need to do is add another text field to the page for the user to enter the password and then verify that entered password against the one stored in the database or wherever it hides. They match, comment gets saved.

That is actually exactly what I want to do, I'm just not sure how to do it.

rosiec 0 Newbie Poster

I have a basic comment page (code below) that I made in Visual Studio 2010 using GridView and FormView. The user fills in the text boxes, the info is put into the database and then inserted into my GridView. I want to password protect the form, so that not only does the person have to enter their name and comment, but they have to supply the correct password.

I know there are many ways to provide some type of password to a page, so any help is much appreciated.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<div id="commentpanel">

   <asp:GridView ID="GridView1" runat="server" CellPadding="4" 
        DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" 
        DataKeyNames="commentor_id" AllowSorting="True" AutoGenerateColumns="False">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:CommandField ShowDeleteButton="True" />
            <asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />
            <asp:BoundField DataField="comments" HeaderText="Comments" 
                SortExpression="Comments" />
            <asp:BoundField DataField="date" HeaderText="Date" SortExpression="date" />
        </Columns>
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#E9E7E2" />
        <SortedAscendingHeaderStyle BackColor="#506C8C" />
        <SortedDescendingCellStyle BackColor="#FFFDF8" />
        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
    </asp:GridView>

</div>

<br />
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" 
        DefaultMode="Insert">
<InsertItemTemplate>
Name: <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("name") %>'></asp:TextBox><br />
Comment (150 characters):<br />
<asp:TextBox ID="txtComments" runat="server" onkeypress="return imposeMaxLength(this, 150);" Text='<%# Bind("comments") %>'
TextMode="MultiLine" Rows="4" Columns="50"></asp:TextBox><br />
<asp:HiddenField ID="hidTimeDate" runat="server" Value='<%# Bind("date") %>' />
<asp:Button ID="butSubmit" runat="server" CommandName="Insert" Text="Submit" />
</InsertItemTemplate>
</asp:FormView>

</ContentTemplate>
</asp:UpdatePanel>