Cross frame dynamic scripting

Results 1 to 2 of 2

Thread: Cross frame dynamic scripting

  1. #1
    Join Date
    Dec 1969

    Default Cross frame dynamic scripting

    I just started playing with .NET and I was hoping it would be able to make something I do a little easier. My approach may be completely wrong so feel free to tell me.<BR><BR>I need to change something in one frame from another but it needs to be determined by some server side action. Imagine in frameleft there is &#060;DIV id=labeltest&#062;&#060;/DIV&#062;. In the frameright I can do:<BR>&#060;SCRIPT&#062;<BR>myDiv=top.frameleft.g etElementsByTagName("DIV")[0];<BR>myDiv.innerHTML = "test";<BR>&#060;/SCRIPT&#062;<BR><BR>What I need to do is have the innerHTML changed with different text. I want to do something like:<BR>&#060;SCRIPT&#062;<BR>myDiv=top.frameleft .getElementsByTagName("DIV")[0];<BR>myDiv.innerHTML = "&#060;asp:Label runat=server&#062;&#060;/Label&#062;";<BR>&#060;/SCRIPT&#062;<BR>but this does not seem to be allowed or at least I can&#039;t get it to work.<BR><BR>Basically I want to have something happen in frameright on the server and pass it to the client frameleft without having to load frameleft over again. The way I do in ASP right now is to use RESPONSE.WRITE to build the JavaScript by hand because you can&#039;t mix client side JavaScript with ServerSide VbScript. So what is the correct way to do this ASP.NET? <BR><BR>Thanks<BR>Jim Guarnotta

  2. #2
    Join Date
    Dec 1969

    Default RE: Cross frame dynamic scripting

    Jim,<BR><BR>This is a common issue that few seem able or willing to discuss. I searched for weeks and left messages on numerous message boards but got little or no response. I finally discovered a method through trial and error that seems to work.<BR><BR>First give your label an id for reference:<BR>"&#060;asp:Label id="lblRef" runat=server&#062;&#060;/Label&#062;". This assumes that this label is in frameright and that is where the action your looking for is going to take place. Set it&#039;s properties to have the same foreground color as the background so that it will not be visible to the user. <BR><BR>Note: If you set Visible = "false" it will not even be generated in the returning HTML so you won&#039;t have access to it on the client side. Setting the foreground color = background color accomplishes the same thing but allows it to be generated.<BR><BR>When the action in the window in frameright occurs set the label.text = "whatever".<BR><BR>Then write a little java script for the windo.onload event for the window in frameright something like the following:<BR><BR>function window_load()<BR>{<BR> var tagobject= document.all._lblRef;<BR> var sLabel = tagobject.innerText;<BR> var myDiv=top.frameleft.getElementsByTagName("DIV")[0];<BR> myDiv.innerHTML = sLabel.text<BR><BR>}<BR>window.onload = window_load;<BR><BR>This is also a good way to change the frame content source in one or both frames based on some user action.<BR><BR>if(lblRef = "change right window to login.aspx") <BR> top.frameright.location.href = "login.aspx";<BR><BR>When you think about it the need for javascript control is obvious. The HTML knows nothing about what happens on the server. You need to be able to set something on the server side that will be visible to the client that will indicate what kind of action to take. The label object is a natural token that can be set on the server side to indicate what action should be taken on the client. The onload event is the natural place to execute the action indicated by the token. <BR><BR>I use this method to control navigation from a table of contents in the left frame and content in the right frame. Just remember that if your using a separate file for your jscript you will need to add a reference to it within the &#060;head&#062;&#060;/head&#062; tags in the controlling window<BR><BR>&#060;HEAD&#062;<BR>...<BR>...<BR>&# 060;SCRIPT language="JScript" src="register.js" type="text/javascript"&#062;&#060;/SCRIPT&#062;<BR><BR>&#060;/HEAD&#062;<BR><BR>I hope this helps. <BR><BR>Ron Cicotte<BR>Summer Street Systems.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts