Can not post data from one page to another page

I am simply trying to successfully enter values on one page (page1.aspx) in a textbox, click a submit button and post those values to another page (page2.aspx). I have a "SQLDataSource1" on page2.aspx with a Datalist control to display data. I thought this would be very simple in ASP.net but it appears to be very complicated. If I place the sqldatasource and the datalist and post the textfield data to itself(page1.aspx) it works with no problems. The problem seems to be posting and retrieving data to another page. If you have the answer please submit working code. I have spent so much time on this already. Here is the code:

page1.aspx code
<div>
   
        <asp:TextBox ID="bodypartmg" runat="server"></asp:TextBox>
   
    </div>
    <div>
        <asp:Button ID="Button1" runat="server" PostBackUrl="~/2post.aspx" Text="Button" />
        </div>
    <div>

page2.aspx code
SQLDataSource1
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SQL2008R2_504887_golivefitnesConnectionString %>" SelectCommand="sp_gettheresults" SelectCommandType="StoredProcedure">
        <SelectParameters>
            <asp:FormParameter FormField="bodypartmg" Name="bodypartmg" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>

Datalist
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
            <ItemTemplate>
                name:
                <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("name") %>' />
                <br />
                bodypartmg:
                <asp:Label ID="bodypartmgLabel" runat="server" Text='<%# Eval("bodypartmg") %>' />
                <br />
             
                <br />

            </ItemTemplate>
        </asp:DataList>
derrekdeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy PooleCommented:
You need to wrap a <form> around your code and submit it
0
derrekdeveloperAuthor Commented:
There is a form wrapped around my code. I didn't include due to me trying to save you from so much reading in the post. However, for anyone else that might think I do not have the controls placed in the form here is the code. I will say though Randy that the answer is a little more complicated than the stab you took at it:

____________________-------------------------------------------------------------___________________________

 <form id="form1" runat="server" defaultfocus="bodypartmg">
    <div>
   
        <asp:TextBox ID="bodypartmg" runat="server"></asp:TextBox>
   
    </div>
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="~/2post.aspx" />
        </div>
    <div>
        </div>
    <div>
   
        </div>
    </form>
0
Randy PooleCommented:
in other words since your page is not performing any serverside validation or callbacks you can use standard html form elements for your initial page:

<form action="/2post.aspx" method="post">
    <div><input type="text" name="bodyparting" id="bodyparting"></div>
    <div><input type="submit" value="Submit"></div>
</form>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

derrekdeveloperAuthor Commented:
Randy, that actually does not work either. There is something more that has to be done on the 2post.aspx code behind page. Simple task like posting data to another page and then displaying results based on the posted data  has always been mine and other people I know big pain with .Net. I know there must be a way to do this with all of the .Net sites but maybe it is something so simple that everyone expects anyone to be able to do it. For now I will assume that you can only post data successfully to the same page. Really sad and I think I will move back to a more flexible tool.
0
Randy PooleCommented:
On Page 2, remove what you have and just place this to verify what is coming across:

<asp:Label ID="bodypartmgLabel" runat="server" Text='<%=Request["bodypartmg"]==null?"":Request["bodypartmg"].ToString();%>' />

Open in new window

0
derrekdeveloperAuthor Commented:
Randy...each solution you offered worked fine. However, I have discovered the true problem. I have done this a thousand times and I knew I could not be doing it incorrectly so...with that in mind. The real problem is using the project creator to create either a new Project or a new Website and elect to allow VS to create all of the plumbing including master pages that have bootstrap and many, many other features cooked right into your code (including using the SiteMaster to create responsive pages that render correctly in smartphones and tablets. I have not quite figured out the settings yet but when you allow VS2013 to create a full project for you it is creating some type of feature (most likely enhanced security) that prevents you from posting and retrieving data from page to page. Or at least in the simple context I am accustomed to doing it. Every since the PostbackURL feature was created for submit buttons I had been successfully utilizing it to post data to other pages. However, there is something that prevents the way I have used this feature in the past. I tested this by creating three empty website projects with VS2013. In each one of those projects the posting data to another page works without any problems. I want to leave this open for a little while because now that I understand what is going on someone may have a little feedback regarding VS2013 Project creation.
0
derrekdeveloperAuthor Commented:
Creating a ASP.Net website project prevented my code from producing the results I expected. This will need further research.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.