• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

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

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
rito1
Asked:
rito1
  • 2
1 Solution
 
zadeveloperCommented:
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
 
rito1Author Commented:
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
 
zadeveloperCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now