•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,563 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,515 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2710 | Replies: 31
![]() |
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
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 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.Text%>"></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
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 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.Text%>"></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
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
Just use your old method. ASP.NET uses server tags in order to process forms VIA the server. And yes, you can only have one SERVER form tag on a page at a time, unless they are in panels which are visible or not.
You can have as many forms as you want on one page, but can only have one server-side form. Your search function does not need to be a server-side form as that you are just posting a querystring. Use the regular form with method "get" without a runat=server.
Use regular form, not runat server
<form method="get" action="selfordiffpage.aspx">
That's all. Just can only have one server-side form.
Oh, but asp controls are server-side form only. So use regular html form tags like <input> instead of asp:TextBox
You can have as many forms as you want on one page, but can only have one server-side form. Your search function does not need to be a server-side form as that you are just posting a querystring. Use the regular form with method "get" without a runat=server.
Use regular form, not runat server
<form method="get" action="selfordiffpage.aspx">
That's all. Just can only have one server-side form.
Oh, but asp controls are server-side form only. So use regular html form tags like <input> instead of asp:TextBox
Last edited by SheSaidImaPregy : Oct 21st, 2007 at 7:16 pm.
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
Thanks so much for your reply, this is driving me absolutely crazy! That was what i tried as i assumed it would work, but the problem i'm having is it only seems to post to the current page, no matter what i do. I thought i couldn't do it because of the other form tag and that's why it was posting back to the same page, but as i say i really don't know anything about ASP.NET! I'm using a masterpage if that makes any difference? My code for the html form is:
<form method="get" action="search2.aspx">
Keyword: <input name="keyword"> Per Page: <select size="1" name="perpage"> <option value="5" selected="selected">5</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option></select><br />
<input type="submit" value="Search" name="Submit"></form>
I would appreciate any ideas you could give so much, this is slowly turning me demented as it should be so easy, but i can't do it. I think i might have to shoot myself because there's just no point if i can't even work this out
Thanks so much mate,
Dave
<form method="get" action="search2.aspx">
Keyword: <input name="keyword"> Per Page: <select size="1" name="perpage"> <option value="5" selected="selected">5</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option></select><br />
<input type="submit" value="Search" name="Submit"></form>
I would appreciate any ideas you could give so much, this is slowly turning me demented as it should be so easy, but i can't do it. I think i might have to shoot myself because there's just no point if i can't even work this out

Thanks so much mate,
Dave
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
Try this to see if it solves your problem. Might be that you are nesting a regular form into a server form, if you are hitting enter though. Try adding this to your submit button:
I have a search function and it is similar to yours, and works. Try using the above one. and post back if you have any questions.
document.forms.formnamehere.submit();
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
Ok, i'm feeling less and less clever as this conversation goes on. In fact i think i might have to go and do an IT GCSE and learn how to turn a computer on. I have now put the following code into my page, which i think is what you meant:
<form name="testform" method="get" action="search2.aspx">
Keyword: <input name="keyword"> Per Page: <select size="1" name="perpage"> <option value="5" selected="selected">5</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option></select><br />
<input type="button" onclick="document.forms.testform.submit();" value="Search" name="Submit"></form>
Unfortunately i get an error on page when i click on the Search button:
'document.forms.testform' is null or not an object
Any ideas?
Thanks so much, you are an absolute diamond,
Dave
<form name="testform" method="get" action="search2.aspx">
Keyword: <input name="keyword"> Per Page: <select size="1" name="perpage"> <option value="5" selected="selected">5</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option></select><br />
<input type="button" onclick="document.forms.testform.submit();" value="Search" name="Submit"></form>
Unfortunately i get an error on page when i click on the Search button:
'document.forms.testform' is null or not an object
Any ideas?Thanks so much, you are an absolute diamond,
Dave
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
sorry, it's javascript. Javascript doesn't do names, so what I meant by formname is formid. Just add the following line to your <form..> statement: id="testform"
It works on id's, not names. Most name attributes will eventually be obsolete. Anyway, just make sure the id of your form is now testform.
It works on id's, not names. Most name attributes will eventually be obsolete. Anyway, just make sure the id of your form is now testform.
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
there's a quickway aruond this that I do not usually like, but works just fine. If you reference it into the current element, you can replace "document" with "this". So essentially, you can eliminate "document.forms.search.submit();" and put "this.form.submit();"
Anyway, I am not particularly fond of it, but it works just as well.
Anyway, I am not particularly fond of it, but it works just as well.
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
You can tell i'm an experienced asp.net programmer can't you
Sorry, this is quite embarassing!
I have made that change, but am still getting the same error as before. Here is my updated code:
<form id="testform" method="get" action="search2.aspx">
Keyword: <input name="keyword"> Per Page: <select size="1" name="perpage"> <option value="5" selected="selected">5</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option></select><br />
<input type="button" onclick="document.forms.testform.submit();" value="Search" name="Submit" id="Button1"></form>
Thanks
,
Dave
Sorry, this is quite embarassing!
I have made that change, but am still getting the same error as before. Here is my updated code:<form id="testform" method="get" action="search2.aspx">
Keyword: <input name="keyword"> Per Page: <select size="1" name="perpage"> <option value="5" selected="selected">5</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option></select><br />
<input type="button" onclick="document.forms.testform.submit();" value="Search" name="Submit" id="Button1"></form>
Thanks
, Dave
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Parent/Child Windows References (JavaScript / DHTML / AJAX)
- Nasties and Enigmas (Viruses, Spyware and other Nasties)
- PostBackUrl (ASP.NET)
- deaktop background stuck with Blue color!! (Viruses, Spyware and other Nasties)
- Posting to same page and re-running javascript (JavaScript / DHTML / AJAX)
- Cross-Page PostBack with grouped RadioButtons (ASP.NET)
- :: Network Within Network :: (Networking Hardware Configuration)
- ISSUES w/Graphics, Video, etc on my aging PC (Motherboards, CPUs and RAM)
Other Threads in the ASP.NET Forum
- Previous Thread: Need help passing database column value to a string variable.
- Next Thread: Image Verification in Asp.net



Linear Mode