User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Oct 2007
Posts: 15
Reputation: deshg is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
deshg deshg is offline Offline
Newbie Poster

Re: Cross page posting confusion

  #11  
Oct 21st, 2007
Hey, i just tried the this.form.submit(); as a replacement within the last code i posted. I get no error this time, but instead it just posts back to the current page, rather than posting to the action page?

Thanks,

Dave
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Cross page posting confusion

  #12  
Oct 21st, 2007
use this code:
<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>
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.
Last edited by SheSaidImaPregy : Oct 21st, 2007 at 9:42 pm.
Reply With Quote  
Join Date: Oct 2007
Posts: 15
Reputation: deshg is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
deshg deshg is offline Offline
Newbie Poster

Re: Cross page posting confusion

  #13  
Oct 21st, 2007
I tried using that code you just posted but i get the:

'document.forms.testform' is null or not an object

error on page again unfortunately ......

Thanks so much for your help, it really is appreciated, you're preventing me from going completely crazy!

Dave
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Cross page posting confusion

  #14  
Oct 21st, 2007
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
Reply With Quote  
Join Date: Oct 2007
Posts: 15
Reputation: deshg is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
deshg deshg is offline Offline
Newbie Poster

Re: Cross page posting confusion

  #15  
Oct 21st, 2007
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
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Cross page posting confusion

  #16  
Oct 21st, 2007
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:
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
Something like that should work as well if it does a postback.
Reply With Quote  
Join Date: Oct 2007
Posts: 15
Reputation: deshg is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
deshg deshg is offline Offline
Newbie Poster

Re: Cross page posting confusion

  #17  
Oct 21st, 2007
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....
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Cross page posting confusion

  #18  
Oct 21st, 2007
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.
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Cross page posting confusion

  #19  
Oct 21st, 2007
you put the page load function on the actual page of search2.aspx or wherever it is just under the above example!
Reply With Quote  
Join Date: Sep 2007
Posts: 1,058
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 61
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Cross page posting confusion

  #20  
Oct 21st, 2007
I have only been practicing asp.net and vb.net since September 27th. Not bad for 3 weeks huh?

I love this stuff. It's just me though!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 5:54 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC