p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Using javascript to open a page (http://p2p.wrox.com/showthread.php?t=68060)

toddw607 May 12th, 2008 10:30 AM

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


dparsons May 12th, 2008 07:50 PM

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
================================================== =========

toddw607 May 13th, 2008 05:35 AM

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") %>' />


dparsons May 13th, 2008 06:16 AM

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
================================================== =========

toddw607 May 13th, 2008 10:25 AM

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


dparsons May 13th, 2008 10:43 AM

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
================================================== =========

toddw607 May 13th, 2008 11:12 AM

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.


dparsons May 13th, 2008 11:35 AM

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
================================================== =========

toddw607 May 13th, 2008 12:02 PM

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!

dparsons May 13th, 2008 12:20 PM

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
================================================== =========


All times are GMT -4. The time now is 04:03 AM.

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