Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old February 20th, 2004, 06:16 PM
Authorized User
 
Join Date: Nov 2003
Location: Norco, CA, USA.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter,

The HtmlForm declaration is removed. But removing it has no effect.

Thanks anyway.



Sandy
Reply With Quote
  #12 (permalink)  
Old February 20th, 2004, 06:32 PM
Authorized User
 
Join Date: Nov 2003
Location: Norco, CA, USA.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Now I'm confused. If the action="SearchResults" in the form of the use of the UC is removed, and it posts back, to which page does it post back, to the UC code page, or to the code page that it's used in, Catalog.aspx.cs?

Originally I'd wanted to have the search action in the UC go directly to SearchResults.aspx.cs, without going to Catalog.aspx.cs. Is there anyway to do that.

Meanwhile I'll follow your suggestions.

Thanks very much.

Sandy
Reply With Quote
  #13 (permalink)  
Old February 20th, 2004, 06:54 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

It posts back to the original page, Catalog.aspx.

However, because the User Control is contained in the page, it will participate in the Post Back. The Page_Load of the control is called, just as the events for the appropriate controls inside the User Control.

One solution is to have the Button_Click for the Search button in the Control redirect the user to the search page, passing the search terms in the QueryString:
Code:
private void btnSearch_Click(object sender, System.EventArgs e)
{
  if (reqSearch.IsValid) // Control Valid?. Just an example
  {
    // Retrieve Search Term and Redirect
    Response.Redirect("/Search.aspx?SEARCH=" + txtSearch.Text);
  }
}
Then inside the Search.aspx, you can retrieve the QueryString, and perform the search.

This way, your User Control can be used on all pages in your site.


HtH,

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #14 (permalink)  
Old February 21st, 2004, 01:47 AM
Authorized User
 
Join Date: Nov 2003
Location: Norco, CA, USA.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Experimentation shows that the <form> works the same whether it's put in the UC or in the page that uses the UC, but it must be in one, and not in both. Second, no matter which file the <form> is in, the execution sequence is first to the code page of that uses the UC, and second to the code page of the UC.
Since the textbox exists in the UC it seems easier to go there to do the redirect to SearchResults.

But this has shown the REAL problem. There's something horribly wrong with SearchResults.aspx. It doesn't go to it's code page even when called directly with an href.

So tomorrow morning I'll begin reworking that whole page.

I really appreciate all your help.

Sandy

Quick-wit: A truck driver was driving along on the highway. A sign comes up that reads, 'Low bridge ahead'. Before he knows it, the bridge is right ahead of him and he gets stuck under the bridge. Cars are backed up for miles. Finally, a police car comes up. The cop gets out of his car and walks around to the truck driver, puts his hands on his hips and says, "Got stuck, huh?" The truck driver says, "No, I was delivering this bridge and ran out of gas."



Sandy
Reply With Quote
  #15 (permalink)  
Old February 21st, 2004, 03:54 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

;)

Well, you could put the <form> inside the UC, but that makes the control pretty hard to reuse. If the UC has its own <form> tag, you can no longer reuse it on pages that have their own <form> tag.

If you skip the form from the UC, you can use it anywhere you want.

If the UC is not just for collecting the data, but also for presenting it, doing the search inside the UC makes perfect sense. The text box could accept a search term, and a DataGrid or some other data control can display the results.

Does SearchResults have the Page_Load event wired up with the code I showed you earlier? There is a bug in VS.NET that drops this code from the InitializeComponent method.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #16 (permalink)  
Old February 21st, 2004, 04:34 PM
Authorized User
 
Join Date: Nov 2003
Location: Norco, CA, USA.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Yes! You are absolutely right. That's a better design for a multi-use UC. However, in this case it's only used in one place and always redirects to SearchResults, which contains the processing for the search string. Also, interesting enough, my original code (the HTMLForm type) in the UC works; and redirects the flow directly to SearchResults without foing to the page in which the UC is used, and without going to the UC code page itself. This seems more efficient. But for general use UC's I'll put the form in the file that uses it.
Yes, the Page_Load in InitializeComponents is there and works fine.

The problem with SearchResults occurs when the search yeilds no results. Then after processing the Page_Load the process blows on the first line in SearchResults.aspx with a "DataItem":
<IMG class=ProductPicture src='Pictures/<%# DataBinder.Eval(Container.DataItem, "visual") %>' border=3>

The Page_Load searchs the database for the search string and returns a DataReader to a DataList.DataSource, and contains:
if (SearchList.Items.Count == 0) {
     ErrorMsg.Text = "No items matched your query.";
}

and there is a asp:Label id="ErrorMsg" at the bottom of the .aspx page, but the process never gets that far.

Sandy

Quick-wit: A lady was picking through the frozen turkeys at the grocery store, but couldn't find one big enough for her family. She asked a stock boy, "Do these turkeys get any bigger?" The stock boy replied, "No ma'am, they're dead."



Sandy
Reply With Quote
  #17 (permalink)  
Old February 22nd, 2004, 05:44 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

I see, but why bother creating a UC when you're only going to use it once? WHy not just embed the necessary controls directly in the aspx page?

The thing with aspx pages is that they always post back to the original page. Your HTML form allowed you to change the action attribute of the form, so you could submit to another page. But with aspx pages, this is just not possible (it will be in the next version of ASP.NET). However, there are some work arounds. Take a look here and here for more information about passing info from page to page. (The second link points to the VS.NET help files, and probably won't work in your browser. You'll need to copy and paste it in the Run dialog or in the address bar of a Windows Explorer.)

Since passing values is a bit complex, I suggested to use the QueryString. IMO, that's a good method to pass info from page to page. Besides, it may turn out to be a benefit for the user as well, as they can bookmark searches that use the QueryString.

What error do you get with the DataBinding? Can you post some more code for the search results, (including the code you used in the aspx for the DataList)?

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #18 (permalink)  
Old February 22nd, 2004, 03:28 PM
Authorized User
 
Join Date: Nov 2003
Location: Norco, CA, USA.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

First, I was wrong about the HtmlForm working. It did at first, but not the next day (after the computer was off for the night). So I'm using your way of putting the VS form in the UC. Does it make any difference at all if this form is in the UC or in the page that uses the UC?

Second, the problem with the SearchResults.aspx page was from sloppy copying and pasting the ItemTemplate was not within the DataList tags. (That really causes strange effects.)

Third, I now have problems with the overall design. After I read your references and study the issure more, I'll probably be getting back to you with a new set of questions.

Your help is very greatly appreciated.



Sandy
Reply With Quote
  #19 (permalink)  
Old February 22nd, 2004, 06:29 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

No, there shouldn't be a difference in functionality. However, for the reasons I mentioned earlier (reuse), it's better to put the form in the page. If you put it in just the UC, you can also no longer use other ASP controls on that page as you can only have one for with the Runat="server".

It's probably a good idea to reconsider your strategy. Maybe things can be done a lot easier. If all you need to do is pass the search terms to another page, the QueryString is fine.
Alternatively, have the Search page submit to itself. That way, the page can collect the search information *and* display the results. IMO, this is the way to go, as you have all your searching stuff together in one page.

Good luck...

Imar




---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Windows User control in Web User Control agarwalvidhu C# 0 March 30th, 2006 01:17 AM
Web User Control Problem jbenson001 ASP.NET 1.x and 2.0 Application Design 12 January 18th, 2005 03:56 PM
Web user control EvilGuyWhoEatsBrains General .NET 1 December 14th, 2004 01:21 PM
Web User Control Best Practices flyin General .NET 4 May 24th, 2004 07:57 AM



All times are GMT -4. The time now is 02:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.