?
Solved

Is it possible to have more than 1 button with different PostBackURLs?

Posted on 2010-01-12
3
Medium Priority
?
254 Views
Last Modified: 2012-05-08
Hi All,

I have an asp.net page that has 1 instance of <form runat="server" id="form1"> but from a user perspective, the page actually has 2 forms available.

What I did was create these 2 forms within form1 but set the Button controls to have different PostBackURLs.

Doing this seems to have stopped both froms from posting without returning any error.

Has anyone came accross this before?.. I have attached a copy of the form's code so that you can see what I have implemented.

Many thanks,

Rit
<form runat="server" id="form1">

<h2>Form #1</h2>
<asp:ValidationSummary ID="ValidationSummary1" CssClass="important" runat="server" ValidationGroup="subs" />
<ul>
<li>
    <input id="area" type="hidden" value="tapestry" runat="server" />
    <input id="other" name="other" type="text" runat="server" />
    <asp:Label ID="Label2" runat="server" Text="Name: " AssociatedControlID="name"></asp:Label>
    <asp:TextBox ID="name" runat="server"></asp:TextBox>
     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="The Name field is Required." Display="None" ControlToValidate="name" ValidationGroup="subs"></asp:RequiredFieldValidator>
    </li>
    <li>
    <asp:Label ID="Label3" runat="server" Text="Email: " AssociatedControlID="email"></asp:Label>
    <asp:TextBox ID="email" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="The Email field is Required." Display="None" ControlToValidate="email" ValidationGroup="subs"></asp:RequiredFieldValidator>
    </li>
    <li>
        <input id="Radio1" name="action" type="radio" value="join" runat="server" />Subscribe
        <input id="Radio2" name="action" type="radio" value="leave" runat="server" />Unsubscribe
        <asp:Button ID="Button1" runat="server" Text="Go" ValidationGroup="subs" PostBackUrl="confirmationsubs.aspx" />
    </li>
</ul>

<h2>Form 2</h2>
<asp:TextBox ID="txtName" runat="server" CssClass="contact-name" Text="Your name..."></asp:TextBox>
  <asp:TextBox ID="txtEmail" runat="server" CssClass="contact-email" Text="Your email address..."></asp:TextBox>
  <asp:TextBox ID="txtQuestion" runat="server" CssClass="contact-question" TextMode="MultiLine" Rows="3" Text="Your message..."></asp:TextBox>
  <asp:ImageButton ID="btnSubmit" CssClass="contact-button" runat="server" ImageUrl="/tapestry/images_core/button_submit_brown_bg.jpg" AlternateText="Submit question" PostBackUrl="confirmation.aspx" />
</form>

Open in new window

0
Comment
Question by:rito1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
zadeveloper earned 2000 total points
ID: 26292314
Try this:
<form runat="server" id="form1">

<h2>Form #1</h2>
<asp:ValidationSummary ID="ValidationSummary1" CssClass="important" runat="server" ValidationGroup="subs" />
<ul>
<li>
    <input id="area" type="hidden" value="tapestry" runat="server" />
    <input id="other" name="other" type="text" runat="server" />
    <asp:Label ID="Label2" runat="server" Text="Name: " AssociatedControlID="name"></asp:Label>
    <asp:TextBox ID="name" runat="server"></asp:TextBox>
     <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="The Name field is Required." Display="None" ControlToValidate="name" ValidationGroup="subs"></asp:RequiredFieldValidator>
    </li>
    <li>
    <asp:Label ID="Label3" runat="server" Text="Email: " AssociatedControlID="email"></asp:Label>
    <asp:TextBox ID="email" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="The Email field is Required." Display="None" ControlToValidate="email" ValidationGroup="subs"></asp:RequiredFieldValidator>
    </li>
    <li>
        <input id="Radio1" name="action" type="radio" value="join" runat="server" />Subscribe
        <input id="Radio2" name="action" type="radio" value="leave" runat="server" />Unsubscribe
        <asp:Button ID="Button1" runat="server" Text="Go" ValidationGroup="subs" PostBackUrl="confirmationsubs.aspx" />
    </li>
</ul>

<h2>Form 2</h2>
<asp:TextBox ID="txtName" runat="server" CssClass="contact-name" Text="Your name..."></asp:TextBox>
  <asp:TextBox ID="txtEmail" runat="server" CssClass="contact-email" Text="Your email address..."></asp:TextBox>
  <asp:TextBox ID="txtQuestion" runat="server" CssClass="contact-question" TextMode="MultiLine" Rows="3" Text="Your message..."></asp:TextBox>
  <asp:ImageButton ID="btnSubmit" CausesValidation="false" CssClass="contact-button" runat="server" ImageUrl="/tapestry/images_core/button_submit_brown_bg.jpg" AlternateText="Submit question" PostBackUrl="confirmation.aspx" />
</form>

Open in new window

0
 
LVL 1

Author Closing Comment

by:rito1
ID: 31676035
Thanks zadeveloper,

I see that adding CausesValidation="false" sorted it but I can't see why I would need this if I have set ValidationGroup on everything that needed it??

Thanks,

Rit
0
 
LVL 13

Expert Comment

by:zadeveloper
ID: 26292645
This is because the imagebutton does not validate and group - which means it validates everything.
Because it does not need to we set causes validation to false.
This is a common problem.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question