Newbie, submit form error on postback

Discussion in 'ASP .Net' started by verci, Feb 8, 2007.

  1. verci

    verci Guest

    Hi guys,

    I'm running VS2005 Professional, SQL Server Express 2005, Win XP Pro SP2,
    ASP.net 2.0, so far I've been stuck for 2 days, thanks in advanced for your
    help.

    I trying to migrate a small forum application build on asp.net 1.1 to
    asp.net 2.0, the problem is when I try to open the form to create a message
    to sent using a form post method and crosspaging via querystring, I get the
    following error :

    A page can have only one server-side Form tag.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: A page can have only one
    server-side Form tag.


    OK, this is the form forum_view.aspx from where I call the form
    message_post.aspx via a hyperlink and passed some values via querystring to
    to message_post.aspx.

    ***************************Forum_view.aspx****************************
    <%@ Page Language="VB" MasterPageFile="~/Default.master"
    AutoEventWireup="false" CodeFile="Forum_view.aspx.vb" Inherits="Forum_view"
    title="Untitled Page" Strict="false" %>

    <%@ Register TagPrefix="Club" TagName="AnimationSmall"
    Src="Animation_Small.ascx" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    Runat="Server">

    <div id="body">

    <Club:AnimationSmall ID="Animation1" runat="server" />

    <div class="fullwidth">

    <asp:label id="forum_name" font-bold="True" font-size="20px" runat="server"
    /><hr />

    <asp:hyperlink id="post_new" text="Nuevo Mensaje" runat="Server" />

    <br /><br />

    <asp:hyperlink id="link_previous" text="&lt;&lt;Anterior" runat="server" />

    &nbsp;|&nbsp;

    <asp:hyperlink id="link_next" text="Siguiente&gt;&gt;" runat="server" /><br
    />

    <asp:repeater id="forum_view1" runat="Server">

    <HeaderTemplate>

    <asp:label font-bold="True" font-size="18px" runat="server" text="Lista de
    Temas" /><hr />

    </HeaderTemplate>

    <Itemtemplate>

    <asp:hyperlink navigateurl='<%# "message_view.aspx?pid=" &
    Container.DataItem.ID & "&fid=" & Request.QueryString("fid") & "&fname=" &
    Server.UrlEncode(Request.QueryString("fname")) %>' text='<%#
    Container.DataItem.SUBJECT %>' runat="Server" />&nbsp;

    (<asp:hyperlink navigateurl='<%# "mailto:" & Container.DataItem.EMAIL%>'
    text='<%# Container.DataItem.NICKNAME %>' runat="Server" />)&nbsp;

    <asp:label text='<%# Container.DataItem.CREATED_DT.Format("G",Nothing) %>'
    runat="server" />

    <asp:label text='<%# "(" & Container.DataItem.REPLY_CNT & " responses)" %>'
    runat="server" />

    <br />

    </Itemtemplate>

    <AlternatingItemTemplate>

    <asp:panel backcolor="lightskyblue" runat="server">

    <asp:hyperlink navigateurl='<%# "message_view.aspx?pid=" &
    Container.DataItem.ID & "&fid=" & Request.QueryString("fid") & "&fname=" &
    Server.UrlEncode(Request.QueryString("fname")) %>' text='<%#
    Container.DataItem.SUBJECT %>' runat="Server" />&nbsp;

    (<asp:hyperlink navigateurl='<%# "mailto:" & Container.DataItem.EMAIL%>'
    text='<%# Container.DataItem.NICKNAME %>' runat="Server" />)&nbsp;

    <asp:label text='<%# Container.DataItem.CREATED_DT.Format("G",Nothing) %>'
    runat="server" />

    <asp:label text='<%# "(" & Container.DataItem.REPLY_CNT & " responses)" %>'
    runat="server" />

    </asp:panel>

    </AlternatingItemTemplate>

    <FooterTemplate>

    <hr />

    </FooterTemplate>

    </asp:repeater>

    <asp:hyperlink ID= "back1" navigateurl="Forum_list.aspx" text="Foros
    Activos" runat="Server" />

    </div>

    </div>

    </asp:Content>

    ******************************Code Behind page
    Forum_view.aspx.vb********************************

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles Me.Load

    Dim ObjCom As SqlCommand

    Dim ObjDataReader As SqlDataReader

    Dim ObjCon As SqlConnection

    Dim myParameter As SqlParameter

    Dim dtSubjects As DataTable

    Dim fid As String

    Dim fname As String

    Dim alSubjects As ArrayList

    Dim page_size As Integer

    Dim start_index As Integer

    Dim end_index As Integer

    Dim IsNext As Boolean

    Dim IsPrevious As Boolean

    fid = Request.QueryString("fid")

    fname = Request.QueryString("fname")

    ObjCon = New
    SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ClubSiteDB").ConnectionString.ToString)

    ObjCom = New SqlCommand

    ObjCom.CommandText = "sp_get_forum_view" '& Request.QueryString("fid")

    ObjCom.CommandType = CommandType.StoredProcedure

    ObjCom.Connection = ObjCon

    myParameter = ObjCom.CreateParameter()

    myParameter.ParameterName = "@Forum_ID"

    myParameter.Direction = ParameterDirection.Input

    myParameter.SqlDbType = SqlDbType.Int

    myParameter.Value = Request.QueryString("fid")

    ObjCom.Parameters.Add(myParameter)

    ObjCon.Open()

    ObjDataReader = ObjCom.ExecuteReader()

    dtSubjects = New DataTable("Subjects")

    dtSubjects.Load(ObjDataReader)

    page_size = 10

    If Request.QueryString("si") = "" Then

    start_index = 0

    Else

    start_index = Int32.Parse(Request.QueryString("si"))

    End If

    end_index = start_index + page_size - 1

    Select Case end_index

    Case Is < (dtSubjects.Rows.Count - 1)

    IsNext = True

    Case (dtSubjects.Rows.Count - 1)

    IsNext = False

    Case Is > (dtSubjects.Rows.Count - 1)

    end_index = dtSubjects.Rows.Count - 1

    IsNext = False

    End Select

    If start_index > (page_size - 1) Then

    IsPrevious = True

    End If

    alSubjects = New ArrayList

    Dim i As Integer

    For i = start_index To end_index

    alSubjects.Add(New ForumSubject(dtSubjects.Rows(i)("ID"),
    dtSubjects.Rows(i)("CREATED_DT"), dtSubjects.Rows(i)("REPLY_CNT"),
    dtSubjects.Rows(i)("NICKNAME"), dtSubjects.Rows(i)("EMAIL"),
    dtSubjects.Rows(i)("SUBJECT")))

    Next i

    'bind the repeater control

    forum_view1.DataSource = alSubjects

    forum_view1.DataBind()

    'set values for other server controls on page

    forum_name.Text = "Foro " & Request.QueryString("fname")

    post_new.NavigateUrl = "message_post.aspx?fid=" & fid & "&fname=" & fname
    ''''''''''''''''''''''''' Here is where I call the message_post page a
    passed the values´'''''''''''''''''''''''''''''''

    If IsPrevious Then

    link_previous.NavigateUrl = "forum_view.aspx?fid=" & fid & "&fname=" & fname
    & "&si=" & start_index - page_size

    End If

    If IsNext Then

    link_next.NavigateUrl = "forum_view.aspx?fid=" & fid & "&fname=" & fname &
    "&si=" & end_index + 1

    End If

    End Sub

    ******************************Message_post.aspx********************************

    <%@ Page Language="VB" MasterPageFile="~/Default.master"
    AutoEventWireup="false" CodeFile="Message_post.aspx.vb"
    Inherits="Message_post" title="Untitled Page" %>

    <%@ Register TagPrefix="Club" TagName="AnimationSmall"
    Src="Animation_Small.ascx" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
    Runat="Server">

    <div id="body">

    <Club:AnimationSmall ID="Animation1" runat="server" />

    <div class="fullwidth">

    <asp:label id="forum_name" font-bold="True" font-size="20px" runat="server"
    /><hr />

    <asp:label id="post_title" font-bold="True" font-size="18px" runat="server"
    /><br />

    <form id="frm_message" runat="server">

    <input type="hidden" id="hidden_pid" runat="server" />

    <input type="hidden" id="hidden_fid" runat="server" />

    <input type="hidden" id="hidden_fname" runat="server" />

    <asp:table ID="Table1" borderwidth="0" cellspacing="0" cellpadding="0"
    runat="Server">

    <asp:tablerow ID="Tablerow1" runat="Server">

    <asp:tablecell ID="Tablecell1" runat="Server">

    <asp:label ID="Label1" font-bold="True" text="Nick:&nbsp;" runat="Server" />

    </asp:tablecell>

    <asp:tablecell ID="Tablecell2" runat="Server">

    <asp:textbox id="txt_nickname" maxlength="20" runat="Server" />

    </asp:tablecell>

    </asp:tablerow>

    <asp:tablerow ID="Tablerow2" runat="Server">

    <asp:tablecell ID="Tablecell3" runat="Server">

    <asp:label ID="Label2" font-bold="True" text="Email:&nbsp;" runat="Server"/>

    </asp:tablecell>

    <asp:tablecell ID="Tablecell4" runat="Server">

    <asp:textbox id="txt_email" maxlength="100" columns="30" runat="Server" />

    </asp:tablecell>

    </asp:tablerow>

    <asp:tablerow ID="Tablerow3" runat="Server">

    <asp:tablecell ID="Tablecell5" runat="Server">

    <asp:label ID="Label3" font-bold="True" text="Tema:&nbsp;" runat="Server" />

    </asp:tablecell>

    <asp:tablecell ID="Tablecell6" runat="Server">

    <asp:textbox id="txt_subject" columns="50" maxlength="50" runat="Server" />

    </asp:tablecell>

    </asp:tablerow>

    <asp:tablerow ID="Tablerow4" runat="Server">

    <asp:tablecell ID="Tablecell7" columnspan="2" runat="Server">

    <asp:label ID="Label4" font-bold="True" text="Mensaje:&nbsp;" runat="Server"
    />

    </asp:tablecell>

    </asp:tablerow>

    <asp:tablerow>

    <asp:tablecell ID="Tablecell8" columnspan="2" runat="Server">

    <asp:textbox id="txt_message" textmode="MultiLine" rows="20" columns="50"
    runat="Server" />

    </asp:tablecell>

    </asp:tablerow>

    <asp:tablerow>

    <asp:tablecell ID="Tablecell9" columnspan="2" runat="Server">

    <asp:button id="btn_post" onclick="btn_post_click" text="Enviar Mensaje"
    runat="server" />

    </asp:tablecell>

    </asp:tablerow>

    </asp:table>

    </form>

    <hr />

    <asp:hyperlink ID="Hyperlink1" navigateurl="Forum_list.aspx" text="Foros
    Activos" runat="Server" />

    &nbsp;|&nbsp;

    <asp:hyperlink id="forum_link" runat="server" />

    </div>

    </div>

    </asp:Content>

    ******************************Code behind
    Message_post.aspx.vb********************************

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    Handles Me.Load

    Dim pid As String

    Dim fid As String

    Dim fname As String

    Dim s As String

    pid = Request.QueryString("pid")

    fid = Request.QueryString("fid")

    fname = Request.QueryString("fname")

    If Not Page.IsPostBack Then

    forum_name.Text = "Foro " & fname

    forum_link.NavigateUrl = "forum_view.aspx?fid=" & fid & "&fname=" & fname

    forum_link.Text = forum_name.Text

    If pid = "" Then

    post_title.Text = "Mensaje Nuevo"

    Else

    post_title.Text = "Respuesta"

    s = "RE: " & Request.QueryString("s")

    txt_subject.Text = s

    End If

    hidden_pid.Value = pid

    hidden_fid.Value = fid

    hidden_fname.Value = fname

    End If

    End Sub

    Protected Sub btn_post_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btn_post.Click

    Dim ObjCon As New SqlConnection

    Dim ObjCom As SqlCommand



    Dim sql As String

    Dim pid As String

    Dim fid As String

    Dim fname As String

    Dim nickname As String

    Dim email As String

    Dim subject As String

    Dim message As String

    pid = hidden_pid.Value

    fid = hidden_fid.Value

    fname = hidden_fname.Value

    nickname = Replace(txt_nickname.Text, "'", "''")

    email = Replace(txt_email.Text, "'", "''")

    subject = Replace(txt_subject.Text, "'", "''")

    message = Replace(txt_message.Text, "'", "''")

    sql = "sp_insert_forum_message " & fid & ",'" & nickname & "','" & email &
    "','" & subject & "','" & message & "'"

    If Len(pid) > 0 Then

    sql = sql & "," & pid

    End If

    ObjCon = New
    SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("ClubSiteDB").ConnectionString.ToString)

    ObjCom = New SqlCommand

    'Setting Command Object

    ObjCom.CommandType = CommandType.Text

    ObjCom.CommandText = sql

    ObjCom.Connection = ObjCon

    ObjCon.Open()

    ObjCom.EndExecuteNonQuery(sql)

    Page.Response.Redirect("forum_view.aspx?fid=" & fid & "&fname=" & fname)

    End Sub
     
    verci, Feb 8, 2007
    #1
    1. Advertising

  2. "verci" wrote:

    > Hi guys,
    >
    > I'm running VS2005 Professional, SQL Server Express 2005, Win XP Pro SP2,
    > ASP.net 2.0, so far I've been stuck for 2 days, thanks in advanced for your
    > help.
    >
    > I trying to migrate a small forum application build on asp.net 1.1 to
    > asp.net 2.0, the problem is when I try to open the form to create a message
    > to sent using a form post method and crosspaging via querystring, I get the
    > following error :
    >
    > A page can have only one server-side Form tag.
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about the error and where it originated in the code.
    >
    > Exception Details: System.Web.HttpException: A page can have only one
    > server-side Form tag.
    >

    <snip>

    Verci,

    I suspect you already have form tag in your master page and don't need the
    <form id="frm_message" runat="server"> in Message_post.aspx. Try removing
    the form frm_message.

    Hope this helps,
    Jason Vermillion
     
    =?Utf-8?B?SmFzb24gVmVybWlsbGlvbg==?=, Feb 8, 2007
    #2
    1. Advertising

  3. verci

    verci Guest

    Hey thaks, that did it!!!!


    "Jason Vermillion" <> wrote in
    message news:...
    > "verci" wrote:
    >
    >> Hi guys,
    >>
    >> I'm running VS2005 Professional, SQL Server Express 2005, Win XP Pro SP2,
    >> ASP.net 2.0, so far I've been stuck for 2 days, thanks in advanced for
    >> your
    >> help.
    >>
    >> I trying to migrate a small forum application build on asp.net 1.1 to
    >> asp.net 2.0, the problem is when I try to open the form to create a
    >> message
    >> to sent using a form post method and crosspaging via querystring, I get
    >> the
    >> following error :
    >>
    >> A page can have only one server-side Form tag.
    >> Description: An unhandled exception occurred during the execution of the
    >> current web request. Please review the stack trace for more information
    >> about the error and where it originated in the code.
    >>
    >> Exception Details: System.Web.HttpException: A page can have only one
    >> server-side Form tag.
    >>

    > <snip>
    >
    > Verci,
    >
    > I suspect you already have form tag in your master page and don't need the
    > <form id="frm_message" runat="server"> in Message_post.aspx. Try removing
    > the form frm_message.
    >
    > Hope this helps,
    > Jason Vermillion
     
    verci, Feb 8, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    6,255
  2. Network-Man
    Replies:
    5
    Views:
    78,525
    gaul1
    Jul 7, 2012
  3. verci

    Newbie, submit form error on postback

    verci, Feb 8, 2007, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    164
    verci
    Feb 8, 2007
  4. verci

    Newbie, submit form error on postback

    verci, Feb 8, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    172
    verci
    Feb 8, 2007
  5. Replies:
    3
    Views:
    707
Loading...

Share This Page