0

Hello I have a bit of ASP.Net Code below. I am trying to figure out how to make my submit button:

 <asp:Button ID="makepost" runat="server" Text="Post My Tip/Story" 
                ValidationGroup="createpost" />

work properly. When I try to add AccessDataSource1.Insert() I get an error saying this:

CS1061: 'ASP.main_aspx' does not contain a definition for 'AccessDataSource1' and no extension method 'AccessDataSource1' accepting a first argument of type 'ASP.main_aspx' could be found (are you missing a using directive or an assembly reference?)

What do I need to type to make this work? All of my code is below.

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:LoginView ID="LoginView1" runat="server">

    <LoggedInTemplate>
        <asp:LoginStatus ID="LoginStatus1" runat="server" />
    <div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color: #FFFFFF">
    <p style="font-size: 20px">Welcome Back!<br />
    Begin Sharing and Reading Space Tips Below!
    </p>



    <p>&nbsp;Current Posts:
        <asp:GridView ID="GridView1" runat="server" DataSourceID="AccessDataSource1" 
            AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
            BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" 
            CellPadding="3" CellSpacing="2" DataKeyNames="ID">
            <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
            <Columns>
                <asp:BoundField DataField="User" HeaderText="User" SortExpression="User" />
                <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                <asp:BoundField DataField="Timeof" HeaderText="Timeof" 
                    SortExpression="Timeof" />
                <asp:BoundField DataField="Post" HeaderText="Post" SortExpression="Post" />
                <asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
                <asp:CommandField ButtonType="Button" ShowEditButton="True" />
            </Columns>
            <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
            <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
        </asp:GridView>

        <asp:AccessDataSource ID="AccessDataSource1" runat="server" 
            DataFile="~/App_Data/Posts.mdb" 
            SelectCommand="SELECT * FROM [UserPost] ORDER BY [Timeof]" 
            DeleteCommand="DELETE FROM [UserPost] WHERE [ID] = ?" 
            InsertCommand="INSERT INTO [UserPost] ([ID], [User], [Title], [Timeof], [Post]) VALUES (?, ?, ?, ?, ?)" 
            UpdateCommand="UPDATE [UserPost] SET [User] = ?, [Title] = ?, [Timeof] = ?, [Post] = ? WHERE [ID] = ?">
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="User" Type="String" />
                <asp:Parameter Name="Title" Type="String" />
                <asp:Parameter Name="Timeof" Type="DateTime" />
                <asp:Parameter Name="Post" Type="String" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:ControlParameter Name="ID" Type="Int32" ControlID="TextBox5" PropertyName="Text" />
                <asp:ControlParameter Name="User" Type="String" ControlID="TextBox1" PropertyName="Text" />
                <asp:ControlParameter Name="Title" Type="String" ControlID="TextBox2" PropertyName="Text" />
                <asp:ControlParameter Name="Timeof" Type="DateTime" ControlID="TextBox3" PropertyName="Text" ConvertEmptyStringToNull="true"/>
                <asp:ControlParameter Name="Post" Type="String" ControlID="TextBox4" PropertyName="Text"  />
            </InsertParameters>
        </asp:AccessDataSource>

    </p>

        <table><tr><td> <asp:Label ID="Label5" runat="server" Text="ID: "></asp:Label></td><td> 
            <asp:TextBox ID="TextBox5" runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr>
        <tr><td> <asp:Label ID="Label1" runat="server" Text="User: "></asp:Label></td><td> 
            <asp:TextBox ID="TextBox1" runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr>
        <tr><td><asp:Label ID="Label2" runat="server" Text="Title: "></asp:Label></td><td><asp:TextBox ID="TextBox2"
                runat="server" ValidationGroup="createpost"></asp:TextBox></td></tr>
        <tr><td><asp:Label ID="Label3" runat="server" Text="Date: "></asp:Label></td><td> <asp:TextBox ID="TextBox3"
                runat="server"></asp:TextBox></td></tr>
        <tr><td valign="top"><asp:Label ID="Label4" runat="server" Text="Story: "></asp:Label></td><td valign="top">
            <asp:TextBox ID="TextBox4" runat="server" Height="129px" Width="474px" TextMode="MultiLine"></asp:TextBox></td></tr>
        </table>
            <asp:Button ID="makepost" runat="server" Text="Post My Tip/Story" 
                ValidationGroup="createpost" /><br />

    </div>

    </LoggedInTemplate><AnonymousTemplate>

        <asp:Login ID="Login1" runat="server" ForeColor="White">
        </asp:Login><br /><div style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; color:#FFFFFF">Please Register to be begin viewing and sharing your 
        <br />Star Wars Old Republic Tips and Stories!</div>
    </AnonymousTemplate>
    </asp:LoginView>
</asp:Content>

3 Answers 3

2

Your AccessDataSource is inside LoginView, you have to find the control:

Dim AccessDataSource1 As AccessDataSource = DirectCast(LoginView1.FindControl("AccessDataSource1"), AccessDataSource)

Regards. in C# it would be this then

AccessDataSource AccessDataSource1 = (AccessDataSource)LoginView1.FindControl("AccessDataSource1");
Sign up to request clarification or add additional context in comments.

4 Comments

the language is C# according to his .aspx header
Come on guys, convert this line of code from VB2C# or C#2VB is easier than write this comment, and if you cant, here is a link you must have developerfusion.com/tools/convert/vb-to-csharp
btw, I am almost sure it works for you, can you mark this as answer?
wich one? maybe we can help you
0
'ASP.main_aspx' does not contain a definition for 'AccessDataSource1'

I think that your AccessDataSource control is located in the wrong place: you've put it in the LoginView. The error message says that the runtime can't find the control in the root of your page. So, try to put the AccessDataSource outside the LoginView.

3 Comments

Did that now getting Method name expected?
I don't understand your question (my English is not very good). Can you clarify? Also, take a look at the answer of Piyey: it's a good suggestion too.
When I do what you suggested (moving the DataSource to outside the LoginView) I get the error:Method Name Expected.
-1

This line. Take a look at:

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 

Do you see AccessDataSource1? Are you perhaps pointing to the incorrect Datasource? Or, did you name it differently and not realize it?

4 Comments

not according to the error.. do a word search within your code to verify.. otherwise why does the error state AccessDataSource1..??\
"Do you see AccessDataSource1?" Yes, I see it: it's the control identifier. The error is other.
what is the other error then because based on what you posted that seem to be the error...
We don't have enough code to make a good diagnostic: Allencoded should provide his C# code behind. At first glance, his ASPX code is good.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.