•
•
•
•
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,565 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,581 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: 2712 | Replies: 31
![]() |
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
use this code:
I do not use masterpages and never have, so that MIGHT be the problem. Use the code above and it should work. If it doesn't I will try to search for an answer for you.
Sorry, what is the exact error you're getting? please let me know.
<form name="testform" id="testform" method="get" action="search2.aspx"> Keyword: <input name="keyword" id="keyword"> Per Page: <select size="1" name="perpage" id="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>
Sorry, what is the exact error you're getting? please let me know.
Last edited by SheSaidImaPregy : Oct 21st, 2007 at 9:42 pm.
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
I have looked into it and it is due to the masterpages. Is there a way that you can design the search INTO the masterpage? Then you won't have a problem.
Otherwise, try trading out:
document.forms.testform.submit();
with:
this.form.submit();
Otherwise you can try writing a javascript function that will be called when pressing the search button.. but that is much harder
Otherwise, try trading out:
document.forms.testform.submit();
with:
this.form.submit();
Otherwise you can try writing a javascript function that will be called when pressing the search button.. but that is much harder
•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
Master pages huh? ASP just makes everything so easy doesn't it
I have tried using this.form.submit(); but then it posts to the current page rather than the one specified in action. I unfortunately can't integrate it into the master page as the search is totally specific to one section of the site and will make no sense if it's displayed on all pages.
I appreciate i have little to no knowlegde of ASP.NET so am not one to condemn it but why on earth have microsoft made such simple procedures so complicated. In pretty much every other web language in the world this is lesson 1. I have been trying to do this now for about 6 hours and i still can't. And whilst i'm extremely un asp proficient i am relatively experienced technically and programming wise so i wouldn't say i'm a novice. Just wondering if there's any reason or if it's the same reason you still can't make proper bullet point lists in word?
I just can't believe there's no way of passing variables easily, i mean it's not exactly an unusual request is it? Gotta love MS.
Also presumably i'm right in thinking if you use javascript then anyone without javascript enabled won't be able to search? And as you say it's much more complicated. I think it might be time to kill myself
I found another suggested method which is:
<asp:textbox runat="server" id="txtKeyword"></asp:textbox><br />
<asp:textbox runat="server" id="txtKeyword2"></asp:textbox><br />
<asp:button runat="server" id="buttonPost" Text="Click" PostBackUrl="search2.aspx"></asp:button>
And then putting:
Request.Form("txtKeyword")
Request.Form("txtKeyword2")
into the page load in search2.aspx. The makes sense as an alternative (i think) if the one we're trying doesn't work, but i'm not sure where or how to specify the page load function on the search2.aspx page and wondered if you could tell me?
I am so so sorry for how absurd this, i cannot reiterate enough how much i appreciate your help, thank you,
Dave
I have tried using this.form.submit(); but then it posts to the current page rather than the one specified in action. I unfortunately can't integrate it into the master page as the search is totally specific to one section of the site and will make no sense if it's displayed on all pages. I appreciate i have little to no knowlegde of ASP.NET so am not one to condemn it but why on earth have microsoft made such simple procedures so complicated. In pretty much every other web language in the world this is lesson 1. I have been trying to do this now for about 6 hours and i still can't. And whilst i'm extremely un asp proficient i am relatively experienced technically and programming wise so i wouldn't say i'm a novice. Just wondering if there's any reason or if it's the same reason you still can't make proper bullet point lists in word?
I just can't believe there's no way of passing variables easily, i mean it's not exactly an unusual request is it? Gotta love MS. Also presumably i'm right in thinking if you use javascript then anyone without javascript enabled won't be able to search? And as you say it's much more complicated. I think it might be time to kill myself

I found another suggested method which is:
<asp:textbox runat="server" id="txtKeyword"></asp:textbox><br />
<asp:textbox runat="server" id="txtKeyword2"></asp:textbox><br />
<asp:button runat="server" id="buttonPost" Text="Click" PostBackUrl="search2.aspx"></asp:button>
And then putting:
Request.Form("txtKeyword")
Request.Form("txtKeyword2")
into the page load in search2.aspx. The makes sense as an alternative (i think) if the one we're trying doesn't work, but i'm not sure where or how to specify the page load function on the search2.aspx page and wondered if you could tell me?
I am so so sorry for how absurd this, i cannot reiterate enough how much i appreciate your help, thank you,
Dave
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
Like I said, I do not use masterpages. Anyway, if by submitting the form normally (type=submit) just does a postback, then what you can do is do an if statement. It would run on page_load like the following:
Something like that should work as well if it does a postback.
Sub Page_Load
Dim content As ContentPlaceHolder
content = Page.Master.FindControl("ContentPlaceHolderName")
Dim TextBox As TextBox
TextBox = content.FindControl("keyword").Text
if TextBox <> "" or Not TextBox = Nothing then
Dim DropDownList As DropDownList
DropDownList = content.FindControl("perpage").Text
response.redirect ("search2.aspx?keyword=" & TextBox & "&perpage=" & DropDownList & "")
end if•
•
Join Date: Oct 2007
Posts: 15
Reputation:
Rep Power: 2
Solved Threads: 0
ah okay that makes sense. Ok really really stupid question now, where do i actually put that page load function, it doesn't seem to like me putting into the .aspx.vb page and i can't put it in the <script> tags as they're within the master page?
Sorry evidently my degree didn't do me much good
Thanks....
Sorry evidently my degree didn't do me much good

Thanks....
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
if you use vb or vb.net, just follow the code below:
<script language="vb" runat="server">
Sub Page_Load
Dim strKeyword As String = Request.QueryString("keyword")
Dim intPerPage As Integer = Request.QueryString("perpage")
if strKeyword <> = "" or Not strKeyword = Nothing then
if intPerPage = "" or intPerPage = Nothing then
intPerPage = "5" 'for results incase no perpage is specified.
end if
'you do not need the following line if you make the literal visible=false in the page.
ltlErrorMessage.Visible = false
'Now you can put it anyway you wish, into a datalist, repeater,
'or grid. I would recommend a repeater, unless you need unlimited
'functionality, then use datalist for it's control options.
else
'not necessarily needed, but extra isn't always bad!
rpSearchResults.Visible = False
ltlErrorMessage.Visible = true
ltlErrorMessage.Text = "There were no keywords specified. Please try again."
end if
End Sub
</script>
<html>
<body>
<asp:Repeater ID="rpSearchResults" runat="server>
<HeaderTemplate>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# DataBinder.Eval(Container.DataItem, "field to show") %></td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td><hr /></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</body>
</html> Last edited by SheSaidImaPregy : Oct 21st, 2007 at 10:37 pm.
![]() |
•
•
•
•
•
•
•
•
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