Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 May 12th, 2008, 10:30 AM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default Using javascript to open a page

Hi,
     I have a pretty strange problem. I am displaying 3 different frames in an aspx page, the top frame is a toolbar, the left frame displays a html page and the third, right frame displays an aspx page. On the right frame I have a datagrid with a link button and once the link button is clicked, it creates the html page, displaying it in the left frame. When the button is initially cliched when the page first loads it works fine however the page does not refresh every time a different link button is clicked. The html page is being created every time but it will not change in the frame. Here is my code:


Code:
 Public Sub Report_Arguments (Src As Object, Args As CommandEventArgs)

Args.CommandArgument & "<br/>"
Dim tempParam As String
tempParam=Args.CommandArgument
 Dim objWriter As New System.IO.StreamWriter("D:\IISRoot\newhtml.html")
objWriter.Write("<HTML><OBJECT CLASSID="+"""clsid:B97E13D0-0BB8-4BCC-85FA-348087269A7E"""+" WIDTH="+"""100%"""+""+ " HEIGHT="+""+"""100%"""+""+"><PARAM NAME="+"URL "+ "VALUE="+"""P:\twhitmarsh\PATHCGMS\"+ tempParam +""""+"></OBJECT></HTML>")
objWriter.Close()
 
MyClick(Args.commandname)
End Sub


  Public Sub MyClick(Byval Index As String) 
  Dim popupScript As String
  popupScript="<script language='javascript'>"+"window.open('IPCGen.aspx?Fig="+ FigNumb + "&Text="+Index + "','ipcframe');<"+"/script>"
  Page.RegisterStartupScript("popupScript", popupScript)
   Dim popupScript2 As String
  popupScript2="<script language='javascript'>"+"window.open('newhtml.html','cgmframe');<"+"/script>"
  Page.RegisterStartupScript("popupScript2", popupScript2)



    The Report_Arguments function is called in the OnClick event of the link button. Any thoughts? TIA

Reply With Quote
  #2 (permalink)  
Old May 12th, 2008, 07:50 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmmm. I have never tried to use window.open() to refresh my frames (of course I don't use frames all that much anyway). I have a couple of suggestions:

First, unless it is necessary to go back to the server after the LinkButton is clicked, use the OnClientClick event of the LinkButton and wire it up like this:

<ItemTemplate>
<asp:LinkButton OnClientClick="javaScriptMethod(); return false;" runat="server" id="LinkButton1" />
</ItemTemplate>

This will prevent a postback.

Next, instead of window.open try:
parent.frames[n].location = 'somepage';

Where n is the number or the name of the frame you want to reload.

hth.
-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #3 (permalink)  
Old May 13th, 2008, 05:35 AM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default

Hi Doug,
     Thanks for the RE:. I was hoping that this was a javascript semantics issue and someone would pick it up so I wouldn't bog
everyone down with unimportant details but I think I'll explain more. The reason why I wanted the link button was so that I could use
the oncommand attribute so I can use VB.NET in order to write a html to a file on the fly and also so I can pass arguments to the function
that is being called from the link button. The problem is that I can only create the file and operate one other task (no idea why). For instance
in my code that is being called from the link button I write the html file and call another method so I can call to other javascript functions
within that function but the only thing about it is that only one will work. I also attempted to set the target of the form to the left frame
and call a Response.Redirect to include what I now want the frame to be but then the javascript function doesn't work. I can unserstand this,
Client Vs. Server, but I know there must be some type of work around for this. Here is my user control in ASP.NET. If you have any more suggestions
please let me know, I think all I need is just a little insight. I'll try the parent frame and if any success I will post back. TIA.
 <asp:LinkButton id="FirstButton" runat="Server" valign="top" text='<%# DataBinder.Eval(Container.DataItem, "Ind") %>' commandname='<%# DataBinder.Eval(Container.DataItem, "Ind") %>' oncommand="Report_Arguments" commandargument='<%# cgm & DataBinder.Eval(Container.DataItem, "Ind") %>' />

Reply With Quote
  #4 (permalink)  
Old May 13th, 2008, 06:16 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Ok, I see what you are doing what you are doing but I am not entirely understanding the problem?

When you click your LinkButton you drop into Report_Arguments, which works, then you drop into MyClick. What I am not clear on is when you say: "The problem is that I can only create the file and operate one other task (no idea why). For instance
in my code that is being called from the link button I write the html file and call another method so I can call to other javascript functions within that function but the only thing about it is that only one will work."

Are you saying only one of the window.open() methods is being called?

Also, this is a bit lengthy for what you are ultimately doing and also Page.RegisterStartupScript is depreciated:
  Dim popupScript As String
  popupScript="<script language='javascript'>"+"window.open('IPCGen.aspx? Fig="+ FigNumb + "&Text="+Index + "','ipcframe');<"+"/script>"
  Page.RegisterStartupScript("popupScript", popupScript)
   Dim popupScript2 As String
  popupScript2="<script language='javascript'>"+"window.open('newhtml.html ','cgmframe');<"+"/script>"
  Page.RegisterStartupScript("popupScript2", popupScript2)

Try this instead

Dim sb as New StringBuilder()
sb.Append("window.open('IPCGen.aspx?Fig="+ FigNumb + "&Text="+Index + "','ipcframe');")
sb.Append("window.open('newhtml.html','cgmframe'); ")

Page.ClientScript.RegisterStartupScript(Me.GetType (), "popupScripts", sb.ToString(), True)

The boolean value of true at the end indicates that the runtime should add the <script></script> tags around your code.

hth.

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #5 (permalink)  
Old May 13th, 2008, 10:25 AM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default

Hi Doug,
       That worked fine for what I was trying to do and I had that working that way earlier however, I still have one
problem with that solution which I forgot to mention. As you know, Once I click on a link button, I drop into
Report_Arguments, which creates a new html file to display in the cgmframe, from there I drop into MyClick, where
the frames are deployed. Everything works fine except the new html file is not displaying. Once the page is initially
launched it works fine but when a different link button is clicked, the html file does not change in the frame. I
checked the file being created (newhtml.html) when Report_Arguments is launched and everything changes in the file
but the frame is not displaying the file. Could this be a Postback issue? Thanks by the way for the snippet earlier.
It is much more concise and this is the first time I've seen it. Do you have any thoughts on something I could try? TIA

Reply With Quote
  #6 (permalink)  
Old May 13th, 2008, 10:43 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hi Todd,
   If you say the file is correctly being created on subsequent postbacks, I think it might be an issue with the frame itself. Have you tried calling reload() on the frame via JavaScript?

Something like:
parent.frames[n].location.reload();

Before you go to the trouble of creating the javascript try manually refreshing the frame, if it works that is your problem. If not then I must consult the Jedi Council further...;]

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #7 (permalink)  
Old May 13th, 2008, 11:12 AM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default

I think JavaScript and I have a strictly love/hate relationship. The html includes an object which displays a LOADING bar when initially launched
so it appears that the page is loading just fine. I added the following snippet into my code and it gave me an error:
Code: sb.Append("parent.cgmframe.location.reload();")
Error: "The page cannot be refreshed without resending the information. Click retry to send the information again, or click Cancel to return to the
page that you were trying to view."
By clicking either one the same error pops up. I can call another function from MyClick and insert a Response.Redirect("newhtml.html") within it and
set the target of the form to cgmframe and that works but then the ipcframe does not update. It will always do one but not both so this leads me
to believe that I am able to do what I want to but it all must rely on loading the newhtml.html in the cgmframe on the fly somehow, just not sure how.

Reply With Quote
  #8 (permalink)  
Old May 13th, 2008, 11:35 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmmm. Something that is a bit of a hack that I have had to use in the past is something like:

parent.frames[n].location.href = 'newpage.html?cusval=' + <some randomvalue>

Some random value can be anything as long as it changes between postbacks.

If this doesn't work for you I will take a look at an app I wrote years ago that utilized the same type of interface though with a few more frames then you are using to see if I have missed anything.

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
Reply With Quote
  #9 (permalink)  
Old May 13th, 2008, 12:02 PM
Authorized User
 
Join Date: Feb 2007
Location: Binghamton, NY, USA.
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to toddw607 Send a message via Yahoo to toddw607
Default

I was thinking of that earlier. I'm not sure how to pass parameters between html files (I'm assuming it's
kinda like asp.net) but I currently add the "Index" parameter to the end of newhtml but before the extension
and because both functions utilize the passed parameter it works! Now I just have to figure out a way to automatically
delete the extra html files when closing out of the ASPX program. Thanks a bunch for your help, I really appreciate it!
Reply With Quote
  #10 (permalink)  
Old May 13th, 2008, 12:20 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can pass parameters to HTML files just as you would an ASPX file through the query string, however, HTML in and of itself can not do anything with this value. While I understand that your solution works, did you try using my solution by appending a value to the query string? I am pretty sure you will get the same result without the need to create additional files.

Something like this:
sb.Append("window.open('newhtml.html?custval=" + Index + "','cgmframe');")

In any event, to handle the issue with the HTML files, I would first delete all of the files out of the directory before creating your new file. This would ensure that there is only ever one file in the directory at a time.

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
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
New window not being open by javascript akhilesh_g Classic ASP Professional 1 September 14th, 2007 04:13 AM
open single select object via javascript nerssi Javascript 8 February 27th, 2006 03:59 PM
JavaScript open pop-up crmpicco Javascript How-To 1 June 10th, 2005 03:40 AM
getURL with javascript window.open properties nancy Flash (all versions) 9 June 4th, 2005 07:52 AM
javascript: window.open & document.documentElement rockon Javascript 2 February 3rd, 2005 04:36 PM



All times are GMT -4. The time now is 06:17 AM.


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