0

I would like it so when a link is clicked on the homepage it would load a particular xml file into the next page (the page is called category-list.apsx).

This category list page uses the Repeater Control method to display the xml details on the page. I used the example shown here:

http://www.w3schools.com/aspnet/aspnet_repeater.asp

So at the moment the repeater script looks like:

<script runat="server"> sub Page_Load if Not Page.IsPostBack then dim mycategories=New DataSet mycategories.ReadXml(MapPath("categories.xml")) categories.DataSource=mycategories categories.DataBind() end if end sub </script> 

After doing some research I did find someone with the same problem and the solution was to insert #tags as part of the link on the homepage (i.e. category-list.apsx#company1results) and then some script on the list page to pick up the correct xml file:

<script type="text/javascript"> var old_onload = window.onload; // Play it safe by respecting onload handlers set by other scripts. window.onload=function() { var categories = document.location.href.substring(document.location.href.indexOf("#")+1); loadXMLDoc('XML/'+categories+'.xml'); old_onload(); } </script> 

This was from the following link:

http://www.hotscripts.com/forums/javascript/45641-solved-specify-xml-file-load-when-click-link.html

How can I get these two scripts to connect with each other?

1 Answer 1

2

It's easier to use a querystring instead of a hash '#', because the querystring will be send server-side, so there is no need of client-side javascript.

So when you call category-list.apsx?cat=company1results, you can use the following code to switch between xml files:

Public Sub Page_Load() If Not Page.IsPostBack Then Dim cat As String = Request.QueryString("cat") Dim mycategories As DataSet = New DataSet() mycategories.ReadXml(MapPath(cat + ".xml")) categories.DataSource = mycategories categories.DataBind() End If End Sub 
Sign up to request clarification or add additional context in comments.

5 Comments

Is there a reason why you dim mycategories as dynamic?
Thank you for the reply Erwin - its currently popping up the following error - Compiler Error Message: BC30002: Type 'dynamic' is not defined. Line 22: Dim mycategories As dynamic = New DataSet()
@Jason: I think it is entirely unnecessary to define mycategories as dynamic. Simply change it to DataSet: Dim mycategories As DataSet = New DataSet()
That seems to work fine now thank you! Are you happy with this update Erwin? If so could you edit your code and I will mark it as correct
@DanielHilgarth I converted C# to VB.Net and I didn't pay attention to the output, but your update is fine by me, thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.