Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Newbie, submit form error on postback

Reply
Thread Tools

Newbie, submit form error on postback

 
 
verci
Guest
Posts: n/a
 
      02-08-2007
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>

<aspanel 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" />

</aspanel>

</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.ConfigurationMa nager.ConnectionStrings("ClubSiteDB").ConnectionSt ring.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.ConfigurationMa nager.ConnectionStrings("ClubSiteDB").ConnectionSt ring.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


 
Reply With Quote
 
 
 
 
Jason Vermillion
Guest
Posts: n/a
 
      02-08-2007
"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
 
Reply With Quote
 
 
 
 
verci
Guest
Posts: n/a
 
      02-08-2007

Hey thaks, that did it!!!!


"Jason Vermillion" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
> "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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert form to submit on load instead of clicking submit button? Network-Man HTML 5 07-07-2012 12:06 PM
submit 1 form to 2 servers or 2 forms to 2 server (1 form each) on 1 submit abansal.itp@gmail.com Javascript 3 06-23-2007 07:29 AM
Newbie, submit form error on postback verci ASP .Net 2 02-08-2007 06:06 AM
Newbie, submit form error on postback verci ASP .Net Building Controls 2 02-08-2007 06:06 AM
submit the form data to the popup window without a submit button jrefactors@hotmail.com HTML 2 01-01-2005 06:07 AM



Advertisments