Connecting Tech Pros Worldwide Forums | Help | Site Map

Cross page posting problems, please help!

Newbie
 
Join Date: Mar 2007
Posts: 5
#1: Oct 21 '07
Hey everyone,

I am a php programmer originally and am just helping a friend of mine update their website that they paid a designer (well that's what he called himself!) to do ages ago. I have built the whole site (ASP.NET using VB.NET) but am having problems on the most basic thing! I have a page which querys an MS SQL database and takes url variables to query it, so it takes the value of keyword= and perpage= (eg from www.site.com?keyword=test&perpage=15) to define a keyword to search for and the number of entries to display on a page. This works perfectly.

All i want is a very simple form (or whatever you want to call it) to pass these variables from another page on my site, so if it was an html form i would just have a form, a text box for the keyword and a pull down box with a few choices for perpage, then a submit button and a post method. Simple. All done.

I tried to do this within Visual Studio but discovered that as all aspx page are effectively forms you can't define another form within so this won't work. Then read up about asp buttons and text boxes and cross page postback (as it needs to send it to another page) and thought that was how to do it. I currently have (ignoring the pulldown box for the moment):
Keyword: <asp:textbox runat="server" id="txtKeyword"></asp:textbox> Per Page: <br />

<asp:button runat="server" id="buttonPost" Text="Click" PostBackUrl="search2.aspx?keyword=<%=txtKeyword.Te xt%>"></asp:button>

This cross posts to the correct page but just has <%=txtKeyword.Text%> as the keyword variable. I have read numerous methods of putting functions within the script tags of the page to read the variables, but i am using a master page so only have one script tag for all pages. I also read all asp buttons use get as their method? I have then read about using the Page.PreviousPage method to retrieve controls from the previous page, which i would rather not do as i want to just pass them simply through the url so as to allow for bookmarking specific searches etc. I am ultimately very confused and think i am missing something as i can't believe that there isn't a simple way of just passing the textbox values as variables through the url. :)

I would really, really appreciate any help anyone could give me, i've been messing about with this and reading up on it for ages and i am stumped, even though i completely appreciate i'm sure i'm being incredibly stupid and i really should have started at the beginning, as i say i'm just trying to help a friend of mine get his website back up.

Thank you so much for any help that you might be able to give, this is beginning to drive me crazy :),

Dave

Newbie
 
Join Date: Mar 2007
Posts: 5
#2: Oct 22 '07

re: Cross page posting problems, please help!


Just in case anyone's interested the following solves the problems (when using asp:button and textbox within your main page):

Protected Sub button_click(....)
Response.Redirect("page2.aspx?text=" & textbox1.text)
End Sub

Dave
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#3: Oct 22 '07

re: Cross page posting problems, please help!


I believe you could also take the runat="server" out of the <form> tag and add regular HTML elements (or just add a new "html document" to the project) and create your form like normal html would.
Reply