Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Can not post data from one page to another page

Posted on 2014-07-10
7
Medium Priority
?
196 Views
Last Modified: 2014-07-16
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>
0
Comment
Question by:derrekdeveloper
  • 4
  • 3
7 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40189163
You need to wrap a <form> around your code and submit it
0
 

Author Comment

by:derrekdeveloper
ID: 40189210
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
 
LVL 21

Accepted Solution

by:
Randy Poole earned 2000 total points
ID: 40189339
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

Author Comment

by:derrekdeveloper
ID: 40190731
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
 
LVL 21

Assisted Solution

by:Randy Poole
Randy Poole earned 2000 total points
ID: 40190812
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
 

Assisted Solution

by:derrekdeveloper
derrekdeveloper earned 0 total points
ID: 40191194
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
 

Author Closing Comment

by:derrekdeveloper
ID: 40198829
Creating a ASP.Net website project prevented my code from producing the results I expected. This will need further research.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

810 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