[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Refresh IFRAME When Calendar Date Changes

I have a web page that contains a calendar control (Cal) and an IFrame (ifCal).  The IFrame displays a page that contains a repeater control (repCalItems), which displays appointments for the selected date. If you select a date in the calendar control, I want the appointments for the selected date to display in the repeater within the IFrame.

I have set up the IFrame in the VB.NET codebehind with the following:

   Protected WithEvents ifCal As System.Web.UI.HtmlControls.HtmlGenericControl

When I click a date on the Calendar control it calls this sub:

Private Sub Cal_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cal.SelectionChanged
      Dim strTransferTo As String

      strTransferTo = "../Calendar/CalItems.aspx?Date=" & Cal.SelectedDate.ToShortDateString
      ifCal.Attributes().Item("src") = strTransferTo

   End Sub

When I run my form I get the following error:

     Object reference not set to an instance of an object.

It fails on this line of code:

      ifCal.Attributes().Item("src") = strTransferTo


What am I doing wrong?
0
rgrimm
Asked:
rgrimm
  • 2
  • 2
1 Solution
 
tusharashahCommented:
Modify your Sub like following:

----------------------------------------------------------------------------------------------------
Private Sub Cal_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cal.SelectionChanged
      Dim strTransferTo As String

      strTransferTo = "../Calendar/CalItems.aspx?Date=" & Cal.SelectedDate.ToShortDateString
        Dim scriptString As String = "<script language=JavaScript>"
        scriptString += "document.getElementById('frameid').src= '" + strTransferTo + "';<"
        scriptString += "/"
        scriptString += "script>"


        Page.RegisterStartupScript("OnChange", scriptString)
   End Sub
----------------------------------------------------------------------------------------------------

-tushar
0
 
rgrimmAuthor Commented:
I am not understanding something. I copy/pasted your code into my program. It runs, but it doesn't do anything, other than append the Javascript to the bottom of the web page containing the calendar. It isn't passing anything to the IFrame.
0
 
tusharashahCommented:
Do you have ID attribute setup in your IFRAME? You need to setup ID of your Frame and replace it with frameid in code:

document.getElementById('frameid')

    <iframe id="frameid" width=300 height=300>
   
    </iframe>

-tushar
0
 
rgrimmAuthor Commented:
Found the problem. I forgot to change your 'frameid' to the name of my frame. Works great!

Thanks!

rick
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now