Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
  #1 (permalink)  
Old January 31st, 2013, 02:02 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default Ch. 15 - AddEditReview page & preselecting genre on Insert?

Hi Imar,

I noticed that the genre is not preselected to the selected genre (on reviews page) when you click on the "Insert New Review" link.

So for example, let's say u selected "Rock" on the Reviews page. The result would be a list of reviews for the "Rock" genre followed by the "Insert New Review" link. When I click on this link, would it be correct to add functionality to preselect the genre on the AddEditRevew page to "Rock"?

I tried doing this by replacing

Code:
<a href="AddEditReview.aspx">Insert New Review</a>
to

Code:
<asp:HyperLink runat="server" Text="Insert New Review" NavigateUrl='<% "~/Management/AddEditReviewHandcoded.aspx?GenreId=" + Eval(DropDownList1.SelectedValue) %>' />
This did not work. Is there a way to do this?

Thank you.

Tulsi
Reply With Quote
  #2 (permalink)  
Old February 2nd, 2013, 07:51 AM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Tulsi,

You can set the URL in Code Behind when the genre changes:

Code:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
  NewReview.NavigateUrl = String.Format("AddEditReviewHandCoded.aspx?GenreId={0}", DropDownList1.SelectedValue);
}
with a HyperLink control like this:

Code:
<asp:HyperLink ID="NewReview" runat="server">Insert New Review</asp:HyperLink>
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old February 4th, 2013, 11:57 AM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Hi Imar,

This worked great! Only thing is that I needed to add

Code:
InsertHyperLink.NavigateUrl = "~/ManageMent/AddEditReview.aspx";
in the page_load for Revews.aspx

to handle the case where no genre was selected. Is this the best way to handle this case?

Thanks.
Tulsi
Reply With Quote
  #4 (permalink)  
Old February 4th, 2013, 12:42 PM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Tulsi,

>> Is this the best way to handle this case?

I think I would prefer to assign the default NavigateUrl in Mark Up:

Code:
<asp:HyperLink ID="NewReview" runat="server" NavigateUrl="~/ManageMent/AddEditReview.aspx";>Insert New Review</asp:HyperLink>
This way, it's more obvious what the default is without the need to scan the code behind.

It's just a preference though; both would work equally fine.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
Tulsi (February 4th, 2013)
  #5 (permalink)  
Old February 4th, 2013, 02:33 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Hi Imar,

Sorry for coming back to this again, but I am running into some other problems..

I'm noticing that as I try to add this new functionality, things are getting more complicated. For example, after selecting the "Insert New Review" link and passing the correct genreId in the query string, I'm trying to pre-select the genre in AddEditReiew.aspx Page_Load. But I do not have access to the genre drop down since it's embedded in the ListView control.

In the previous ex. I acessed the genre value by using e.Values["GenreId"] in the drop_down event, but not sure what to do in this case?

This made me go back to p. 554 and think of the line...
Quote:
"The final issue I often encounter when working with the data controls is that I do not have complete control over the markup they create"
. I did not completely understand this when I read it at the time, but now I think I do after running into the problem with not being able to access the drop down for genre. Is my thinking correct? Is this the type of issue you had in mind?

Also, is there a solution to this problem for the AddEditReview page, or in this case would I have to use the AddEditReviewHandCoded implementation to be able to pre-select the genre Id?

Thank you so much for all your help.

Tulsi
Reply With Quote
  #6 (permalink)  
Old February 4th, 2013, 03:04 PM
Imar's Avatar
Wrox Author
Points: 72,019, Level: 100
Points: 72,019, Level: 100 Points: 72,019, Level: 100 Points: 72,019, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,075
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Tulsi,

Quote:
but not sure what to do in this case?
You can set the SelectedValue, like this:

Code:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="GenresDataSource" DataTextField="Name" DataValueField="Id" SelectedValue='<%# Request.QueryString.Get("GenreId") %>'>
Alternatively you can use FindControl on the DetailsView to find the DropDownList and then preselect the item. Either way, this is a bit messy and that's why I prefer the hand coded alternative for more complex pages.

Quote:
Is this the type of issue you had in mind?
Not completely. I was referring to the final HTML that gets generated by the controls. For example, the GridView generates a lot of HTML on its own, without an easy way to fully control what it generates.

The issue you ran into now could easily have been added as a fourth problem with the controls.... ;-)

Cheers

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #7 (permalink)  
Old February 5th, 2013, 03:20 PM
Friend of Wrox
Points: 595, Level: 8
Points: 595, Level: 8 Points: 595, Level: 8 Points: 595, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2011
Posts: 126
Thanks: 39
Thanked 2 Times in 2 Posts
Default

Thank you again :) This was very helpful!

Tulsi
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
CH 17 Storing Genre Preferences in the Profile - Error! leeWozyWarren BOOK: Beginning ASP.NET 4 : in C# and VB 3 December 7th, 2011 01:20 PM
preselecting dropdownlist item yasminnnnn ASP.NET 2.0 Professional 1 December 26th, 2006 06:52 AM
Masked Elements; Page 815; Ch 15 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 July 24th, 2006 02:12 PM
Time & date insert and display in myql/asp page karib MySQL 3 June 30th, 2004 05:29 AM
CH.15 NEED HELP stacy BOOK: Beginning ASP 3.0 1 January 21st, 2004 03:37 AM



All times are GMT -4. The time now is 03:53 AM.


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