locked
Getting values from ASPX page via hyperlink RRS feed

  • Question

  • Hi,

    I have a solution with two projects; one in Silverlight and the other ASP.NET.

    I have a hyperlink on an aspx page which passes a value which is the hyperlink itself - i.e. 1001 is the link and '1001' is the value I want to pass:

    <asp:HyperLink ID="hplRoomNumber" runat="server"onclick="window.open (this.href,'popupwindow','width=1150,height=900,scrollbars,resizable'); return false;"> [hplRoomNumber]</asp:HyperLink><br />

    I've set the value in my code behind here:

    hplRoomNumber.NavigateUrl = "OfficeLocatorTestPage.html?RoomNumber=" + StrRoomNumber;

    The problem is to receive this value in my xaml code behind.

    I've been told that this is not possible as Silverlight can only use web services (?)  Is that right?

    thanks,

    Paul

    Thursday, September 3, 2009 3:34 PM

Answers

  • What is "<value>"?

    Yes, that was what I was getting at; what should be the variable "<value>".  Anyway, I made some changes and it "works". 

    I put the statement:

    string offNumber = System.Windows.Browser.HtmlPage.Document.QueryString["RoomNumber"];

    in App.xaml.cs and passed it to my main page:

    private void Application_Startup(object sender, StartupEventArgs e)

    {

    this.RootVisual = new MainPage(offNumber);

    }

    I found that trying to access "RoomNumber" in MainPage would work but was then overwritten when Application_Startup was called.  That was why I was getting the error that the key was not found in the dictionary.

    Friday, September 4, 2009 12:42 PM

All replies

  • What are you trying to do? You have an aspx which has a hyperlink. From your code I can tell when you click this link, it should popup a new window.  What is the relationship between Silverlight control and this apsx page? Is the Silverlight control in the same aspx page? What value do you want to pass to the Silverlight control? 

    If you want to use your Silverlight control in your aspx page, you need to Add a Silverlight on your ASP.NET Web project, Go to the project property page of your ASP.NET project, on the Silverlight Application Tab, add a Silverlight link, point to your Silverlight project. 2 Test pages (one html, one aspx) will be generated in your ASP.NET project. You can first use one of the Test pages to test your Silverlight project. Take a look at the source in the Test html page. You would understand how you embed a Silverlight control in a page.

     

     

     

    Thursday, September 3, 2009 4:19 PM
  • What is the relationship between Silverlight control and this apsx page?

    There is no relationship and that's the problem.  

     

    Is the Silverlight control in the same aspx page?

    As I stated, I have 2 distinct projects; one is ASP.NET and the other is Silverlight.  I want to pass the RoomNumber value from an aspx file to my Silverlight project.  I don't want to embed a Silverlight control into an aspx file, it's almost the opposite.

    So, the RoomNumber value is assigned in my ASP project.  I want to pass RoomNumber to a xaml page (with C# code behind) so that I can use this value in my Silverlight project.

    I currently have a web service that can generate data (room numbers) which is consumed by Silverlight but I don't have a user selected value.

    What I need is to get the room number value selected by the user from an aspx page, pass that value to Silverlight and use it in my xaml page.

    Using QueryString from aspx to Silverlight doesn't seem to work as Silverlight doesn't work with System.Web so I don't know what else to do.

    Thursday, September 3, 2009 4:40 PM
  •  

    What is the relationship between Silverlight control and this apsx page?

    There is no relationship and that's the problem.  

     

    Is the Silverlight control in the same aspx page?

    As I stated, I have 2 distinct projects; one is ASP.NET and the other is Silverlight.  I want to pass the RoomNumber value from an aspx file to my Silverlight project.  I don't want to embed a Silverlight control into an aspx file, it's almost the opposite.

    So, the RoomNumber value is assigned in my ASP project.  I want to pass RoomNumber to a xaml page (with C# code behind) so that I can use this value in my Silverlight project.

    I currently have a web service that can generate data (room numbers) which is consumed by Silverlight but I don't have a user selected value.

    What I need is to get the room number value selected by the user from an aspx page, pass that value to Silverlight and use it in my xaml page.

    Using QueryString from aspx to Silverlight doesn't seem to work as Silverlight doesn't work with System.Web so I don't know what else to do.

    From your post I'm afraid you don't understand how Silverlight works. Silverlight control need to be embedded in a HTML/aspx web page for it to work. You can not load a xaml directly into a browser and expect it to work.

    I'm not sure what you really want. I can only guess from your post:

    You have a link on an aspx page, and you want this link to open a new window. In that new window it's your Silverlight application. And you need that Silverlight application aware which RootNumber you passed in the query string.

    If this is what you want, you can do the following:

    1) Follow the steps I posted in my first post to add a Silverlight link to your ASP.NET project.

    2) In your ASXP page,  make sure the URL of that hyperlink point to the newly added TestPage.html. So when you click the link, the new window opens and load the TestPage.html which contains your Silverlight applicaiton.

    3) In your Silverlight control code, you can access the page query string by this:

    string roomNumber =  System.Windows.Browser.HtmlPage.Document.QueryString["RoomNumber"];

     

     

     

     

     


    Thursday, September 3, 2009 5:13 PM
  • Well, that's not quite true.  I do know, to some degree, how Silverlight works.  I don't know it all which is why I'm posting on these forums.

    Most of the steps you posted were already done. I had set the properties and have test pages.  What I didn't know, however, was the last part

    string roomNumber =  System.Windows.Browser.HtmlPage.Document.QueryString["RoomNumber"];

    So, thanks for that.  However, I'm still getting an error. 

    string roomNumber = System.Windows.Browser.HtmlPage.Document.QueryString["<value>"];

    The error is that the given key is not present in the dictionary.  I thought <value> would be the id of the control.  What should this be?

    thanks,

    Paul

    Thursday, September 3, 2009 6:43 PM
  • What is "<value>"?

    What does your URL look like. If your URL ="http://yourSite/YourTestPage.html?RoomNumber=5"   

    Then you can get that "5" by

    string roomNumber = System.Windows.Browser.HtmlPage.Document.QueryString["RoomNumber"];

     

     

    Thursday, September 3, 2009 8:23 PM
  • What is "<value>"?

    Yes, that was what I was getting at; what should be the variable "<value>".  Anyway, I made some changes and it "works". 

    I put the statement:

    string offNumber = System.Windows.Browser.HtmlPage.Document.QueryString["RoomNumber"];

    in App.xaml.cs and passed it to my main page:

    private void Application_Startup(object sender, StartupEventArgs e)

    {

    this.RootVisual = new MainPage(offNumber);

    }

    I found that trying to access "RoomNumber" in MainPage would work but was then overwritten when Application_Startup was called.  That was why I was getting the error that the key was not found in the dictionary.

    Friday, September 4, 2009 12:42 PM
  • You can prevent that "the given key is not present in the dictionary" error by using the ContainsKey method:

    string roomNumber = string.Empty;
    if
    (HtmlPage.Document.QueryString.ContainsKey("RoomNumber"))
    {
    roomNumber = System.Windows.Browser.HtmlPage.Document.QueryString["RoomNumber"];
    }

     

    Wednesday, December 9, 2009 12:09 PM