Can someone please help me with why this button is not working, I've tried putting it in <for id="" runat="server">, but then I get the error: A page can have only one server-side Form tag.

When the button is clicked nothing happens.

<%@ Page Language="C#" MasterPageFile="~/train.master" AutoEventWireup="true" validateRequest="false" 
CodeFile="TrainStationTutorial.aspx.cs" Inherits="TrainStationTutorial" Title="Admin | Tutorial" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <link href="style2.css" rel="stylesheet" type="text/css" />

<div id="main">
       <object width="740" height="207" >
            <param name="movie" value="admin_menu.swf" />
            <embed src="images/admin_menu.swf" width="960" height="170" />
        <h2>Admin | Tutorial</h2>
        <br />
        <div class="about">
            <div class="contactform">
                <div id="li1">
                    <asp:Label ID="titleLabel" runat="server" Text="Title" CssClass="label" />
                    <asp:TextBox ID="titleText" runat="server" CssClass="inputtext" />
                <div id="li2">
                    <asp:Label ID="categoryLabel" runat="server" Text="Category" CssClass="label" />            
                    <asp:ImageButton ID="addCategory"  runat="server" ImageUrl="images/add.jpg" /> 
                <div id="li3">
                    <asp:Label ID="tutorialLabel" runat="server" Text="Tutorial" CssClass="label" />
                    <asp:TextBox ID="tutorialArea" runat="server" CssClass="textarea" TextMode="MultiLine" />
                <div id="li4">
                    <asp:ImageButton ID="submitButton"  runat="server" ImageUrl="images/submit.jpg" OnClick="ImageButton1_Click" /> 
				    <asp:Label ID="messageLabel" runat="server" Font-Size="10px" ForeColor="Red" />
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        messageLabel.Text = "Working";

Recommended Answers

All 11 Replies

some times this kind of bug comes try restarting Your project usuali i am facing same problem

I'm actually confused because the code snippet you've provided doesn't appear to have anything 'out of the ordinary' to it that I can see from first glance. Coupled with the fact that you have NO form tag that I can see, I'm not sure why you'd be getting the error that you can only have 1 form tag.

The last time I got the error "A page can have only one server-side Form tag." it was because I had a braindead moment and forgot how to separate content with panels and tried to do it with forms :twisted:

That being said... having 0 form tags may cause issues with trying to run ASP.Net server side scripting ;)

Can you have a look at the master page, maybe I'm missing something. I've tried different machines and same thing.

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="train.master.cs" Inherits="train" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Train Station</title>
<link href="style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="js-style.css" type="text/css" media="screen" />
  	<link rel="stylesheet" href="fx.slide.css" type="text/css" media="screen" />
	<script type="text/javascript" src="js/mootools-1.2-core-yc.js"></script>
	<script type="text/javascript" src="js/mootools-1.2-more.js"></script>
	<script type="text/javascript" src="js/fx.slide.js"></script>    

    <div id="login">
		<div class="loginContent">
			<form action="#" method="post" runat="server">
				<label for="log"><b>Username: </b></label>
				<input class="field" type="text" name="log" runat="server" id="log" value="" size="23" />
				<label for="pwd"><b>Password:</b></label>
				<input class="field" type="password" name="pwd" runat="server" id="pwd" size="23" />
				<input type="submit" name="submit" value="" class="button_login" onclick="submitButton_Click"/>
				<input type="text" name="redirect_to" value="" runat="server" />
			<div class="left">
            	<label for="rememberme"><input name="rememberme" id="rememberme" class="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label></div>
			<div class="right">Not a member? <a href="Register.aspx">Register</a> | <a href="#">Lost your password?</a></div>
		<div class="loginClose"><a href="#" id="closeLogin">Close Panel</a></div>
	</div> <!-- /login -->

    <div id="containerl">
		<div id="top">
		<!-- login -->
			<ul class="login">
		    	<li class="left">&nbsp;</li>
		        <li>Hello&nbsp; <asp:Label ID="status" runat="server" Text=" Guest" /></li>
				<li><a id="toggleLogin" href="#">Log In</a></li>
			</ul> <!-- / login -->
		</div> <!-- / top -->
	</div><!-- / container -->
	<div class="clearfix"></div>

    <div id="container">
        <object width="593" height="47" style="padding:0 0 10px 350px">
                    <param name="movie" value="menu.swf" />
                    <embed src="images/menu.swf" width="593" height="47" />
    <!-- header -->
    <div id="header">
         <div id="logo"><a href="#">Train Station</a></div>
            <div id="submenu"> 
                <%-- create --%>
    <!--end header -->
    <!-- content -->
        <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
            <div id="text">
     <!-- end content -->
    <!-- footer -->
    <div id="footer">
    <div id="right_footer">
        Designed by Geraldine Underhay
    <!-- end footer -->

I could be missing something, or the fact that it's 2:45am and I'm about ready to pop off to bed could be influencing the clarity of my thinking.

That being said, I'm also not an "expert" so much as I'm good at finding the answers I need as I need them while I'm coding :twisted:

I say all this so you can take my next bit in context as having a 50/50 chance of being a total crock 'o sh*t hehe

Personally, I'm used to the <form> tags encompassing all of the interactive (read: components within my pages. I'm also used to every <form> tag that's related to ASP.Net components having an id. When I look at your code it looks like you have a login content segment which has an enclosed form segment but that you also have a separate contentplaceholder segment which I will assume relates to your earlier code segment where there are form elements that are not in any way encapsulated within a form element.

Beyond that bit of speculation, I can't help you but maybe I'll have more luck in the morning if you're still having issues then :)

grab all runat = "server" controls inside form tag.
on master page..

it should work..

Your button controls are outside form tag . Try adding inside it. It will work.

I guess we have already discuss about similar topic here

I restructed all the pages. All works now

Glad you got it sorted :) Was the problem based on what was suggested above or something else? I'm just curious.

Ok, I basically put a form tag in the master page for all the content, if you look at my master page I've only got a form tag for the login, Which does not apply to the ContentPlaceHolder.


You can refer the following code.

loginButton.Attributes.Add("onclick", "window.showModalDialog('/MyWebsite/login.aspx', null, 'status:no; dialogWidth:360px; dialogHeight:229px; help:no; scroll:no; menubar:no; resizable:no')");

It will help you to solve the issue of button not working.

Hi Jellybeannn!
I already have My "Content Panel" surrounded by "Form" tag.
But i am still facing the same prOblem :-(

Plz tell Me Have You changed any other property of Your "ImageButton" or "Page"..?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.