BMW
BMW

Reputation: 630

asp.net form in both master and content page


I have a problem with my asp.net webform I have two from(exclude default form that added automatically) one master page and the other in content page bu when I submit the second one only the first one get submited:
master page:

 <form  method="GET" action="Search.aspx" >
    <div id="searchform" class="search-form">
        <input type="text" id="txtSearch" name="txtSearch" style="height: 20px;" placeholder="ووشەی گەران لێرەدا بنووسسە" class="search-input placeholder" />
        <input type="submit" id="btnSearch" class="btn" name="btnSearch" value="بگەرێ" />
        <br />
        <span style="text-align: center; padding-top: 2px; padding-right: 100px;">
            <select id="DropDownListItems" name="cat">
                <option value="0">ناونیشان</option>
                <option value="1">کۆمپانیا</option>
                <option value="2">ووڵات</option>
                <option value="3">جۆری کار</option>
                <option value="4">شار</option>
                <option value="5">هەمووی</option>
            </select>
        </span>
    </div>
</form>

Content page:

 <div id="element_to_pop_up" style="text-align: center;">
          <form method="POST" action="AddJob.aspx">
             <h2>جۆری کار</h2>
             <p>
                 <span id="txtJobTypeSpan" style="color: red;"></span>

                 <input type="text" name="jobname" id="jobname"/>
             </p>
             <p>
                 <input type="submit" name="btnAddJobCat" value="submit"/>

             </p>                      
          </form>              
     </div>

Upvotes: 1

Views: 3436

Answers (3)

Ahmed M. Musaeed
Ahmed M. Musaeed

Reputation: 11

make all controls as ASP.NET controls and add deferent name for ValidationGroup attribute to each button

in MasterPage:

<form  method="GET" action="Search.aspx" id="form1" runat="server" >
<div id="searchform" class="search-form">
    <input type="text" id="txtSearch" name="txtSearch" style="height: 20px;" placeholder="ووشەی گەران لێرەدا بنووسسە" class="search-input placeholder" />
    <input type="submit" id="btnSearch" class="btn" name="btnSearch" value="بگەرێ" />
    <br />
    <span style="text-align: center; padding-top: 2px; padding-right: 100px;">
        <select id="DropDownListItems" name="cat">
            <option value="0">ناونیشان</option>
            <option value="1">کۆمپانیا</option>
            <option value="2">ووڵات</option>
            <option value="3">جۆری کار</option>
            <option value="4">شار</option>
            <option value="5">هەمووی</option>
        </select>
    </span>
</div>

put ContentPlaceHolder control in the place that you want ContentPage to placed

in ContentPage:

    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">     
    <div id="element_to_pop_up" style="text-align: center;">
              <form method="POST" action="AddJob.aspx">
                 <h2>جۆری کار</h2>
                 <p>
                     <span id="txtJobTypeSpan" style="color: red;"></span>

                     <input type="text" name="jobname" id="jobname"/>
                 </p>
                 <p>
                     <input type="submit" name="btnAddJobCat" value="submit"/>

                 </p>                      
              </form>              
         </div>
</asp:Content>

ContentPage should not have form tag. all your codes should be in Content Tag

Upvotes: 0

EdSF
EdSF

Reputation: 12341

You cannot nest forms which is what you are doing when you add another <form/> element in your Content page. It will be nested inside the server side form of the Master Page.

Remove the <form/> element in your Content Page and make use of Button.PostBackUrl if you need to POST to some other action instead of a Postback.

Upvotes: 2

codingbiz
codingbiz

Reputation: 26386

Try changing the second form to this:

<input type="button" name="btnAddJobCat" value="submit" onclick="document.forms[1].submit()" />

OR

<input type="button" name="btnAddJobCat" value="submit" onclick="document.getElementById('element_to_pop_up').submit()" />

Upvotes: 0

Related Questions