Thursday, March 29, 2012

Popping up a window

Hi,

I'm writing a page in asp.net to post something to a website and I'm trying to add a preview button to the page. The problem with the code lies in popping up a window containing the preview. The onClick event of the asp:button runs a subroutine to create a new text file, 'temp.txt' (using a Try... Catch statement). Once this is done, I have added the following line:
message.Text = "<script language=Javascript>window.open('disp_report.asp?temp.txt');</script>", where message is an asp:label. This results in a Compilation Error saying 'Try statement must end with an 'End Try', almost as if the line of code was an unterminated string. Commenting out the line (with a ') results in the same error.

Any ideas?Can you post your code as you have it in the IDE?
How much do you want? The whole page?
Here's the page (attached). The line of code I mentioned is commented out at the bottom of the Preview_Click subroutine. It still causes the error, though. For the moment, I've got the message label showing a hyperlink to view the preview, which is a bit messy, but works.
I cant get the attachment, says invalid. Can you make it a textfile?
Done before you posted ;)
Ah, ok. I was getting the forums source for this page :lol:
Let me see what you got now.
I edited the post with the aspx attachment, removed that and added the text file instead.
Don't set the label's text to that script.

To popup a window, in the button's click event, after generating the file, do this:

Page.RegisterStartupScript("script1","<script language=Javascript>window.open('disp_report.asp?temp.txt');</script>")

That is the way to do it.
Thanks for helping froggy. I was stuck on this.

I fed you earlier so you'll have to wait for the next mealtime. :D
In case you haven't noticed by now, I like microwaved cheese sandwiches :afrog:
Thanks for that.

How do I then remove the Startup script so that it doesn't fire again when they click Save?
No, that hasn't worked... still giving me the same error.

Putting it outside of the Try statement throws up:
'BC30648: String constants must end with a double quote.'

And the calendar control keeps going Italian on me!
Okay, building up the string gradually has shown that the problem seems to be with the final ">". However,
Dim strScript As String
strScript = "<script language=Javascript>window.open('disp_report.asp?temp.txt');</script" & ">"
Page.RegisterStartupScript("script1", strScript) seems to work.

Weird...

This still isn't giving me a popup, either. Searching the page source after the button has been clicked shows that the script is there, right after the 'Temporary match report created...' on the page. Any more ideas?

**Edit**

Turns out, the popup works fine - Norton Internet Security is just blocking it! Any way round this? I'm still having the Italian calendar problem, too.
Any popup blockers in place?
Norton Internet Security is the culprit. Is there any way round this? I can add an exception on my computer, but it's not really feasible for everyone visiting using Norton to do.

I'm still getting the Italian calendar from time to time, too!
For the first part, do you really need the popup to open when the page reloads, or can you have it when the user clicks on the link? Things could be easier if it's on the link click.

For the second part, how Italian is it? Is it romancing you?
Well, it would look better if the page popped up, but it's not essential.

As for the calendar, I've attached an image.
Oh, it's going Italian on you, literally.

I thought you were using a cliche or euphemism for "It's trying to kill me." :sick:

For the calendar, check your regional settings in Control Panel.
My regional settings are fine. It's just bizarre that the calendar control is only sometimes Italian... It's something like 1 time in 5 that it appears like that!

**Edit**

The following lines of code seem to have fixed it:

Sub Page_Load()
Dim lang As System.Globalization.CultureInfo
lang = New System.Globalization.CultureInfo("en-gb")
System.Threading.Thread.CurrentThread.CurrentCulture = lang
System.Threading.Thread.CurrentThread.CurrentUICulture = lang
End Sub

Back to the original question - can you think of a reason why I had to concatenate on the last '>' like that?
No, I can't think of any. You shouldn't even have to do that. It maybe a simple double quote problem that we're overlooking.
Dont you need to use the escape char when using the "/"?
Not for asp.net, surely? It should treat everything within the quotation marks as a string literal and that's it...
The escape characters would be in use in C# codebehind, but he's got VB.NET there.
Dont you need the escpae char for the JavaScript is what I was meaning.
If it were in the javascript code itself, yes. :D
Well, I suppose I should mark this resolved. We got the popup going, although no resolution about that last '>'. I've actually seen that in some code before - where it's added on at the end, but there was no explanation as to why. I just thought, 'that looks pointless...' and left it at that.

0 comments:

Post a Comment