Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening multiple windows from code behind

Status
Not open for further replies.

teclioness

Programmer
Jul 12, 2000
5
GB
Hi,

I am making a web applications, where the users can post new messages for everyone to see (in their department). Every one minute the show messages page checks for new message and needs to show popup window with some part of the new message that has been posted.

I have been able to show one popup window using response.write method and writing javascript window.open code in it. Even the RegisterStartupScript method works fine.

The problem is if in case there are 2 or more messages being posted in that 1 minute time, I need to show multiple popup windows. How can I do that?

code is as follows, which I am running in a loop:

Dim strWinName As String = "win"
Dim intWin As Integer = Request.QueryString("id")
Dim strConcatWinName As String = strWinName + CStr(intWin)
Dim strMessText As New StringBuilder
strMessText.Append(strConcatWinName + ".document.write('<html><head><title>New message notification!!</title>');")
strMessText.Append(strConcatWinName + ".document.write('<link rel=""stylesheet"" href=""../styles/style.css"">');")
strMessText.Append(strConcatWinName + ".document.write('</head><body onBlur=""self.focus()"">');")
strMessText.Append(strConcatWinName + ".document.write('<p>Hello test</p>');")
strMessText.Append(strConcatWinName + ".document.write('<p>" + strConcatWinName).Append("</p>');")
strMessText.Append(strConcatWinName + ".document.write('<p>Close the popup.</p>');")
strMessText.Append(strConcatWinName + ".document.write('</body></html>');")
strMessText.Append(strConcatWinName + ".document.close();")

Dim strPopUp As New StringBuilder
strPopUp.Append("<script language='javascript'><!--" + Chr(10) + Chr(13))
strPopUp.Append("var w = 480, h = 340; var popW = 500, popH = 400;")
strPopUp.Append("var leftPos = (w-popW)/2, topPos = (h-popH)/2;")
strPopUp.Append("var strFeatures = ""titlebar=no,toolbar=no,resizable=yes,status=yes,me nubar=no,scrollbars=yes, left="" + leftPos + "",top=""+ topPos;")
strPopUp.Append("strFeatures = strFeatures + "", width="" + popW + "",height="" + popH;")
strPopUp.Append(strConcatWinName + " = window.open('', ""win"", strFeatures);")
strPopUp.Append(strMessText.ToString)
strPopUp.Append(strConcatWinName + ".focus();" + Chr(10) + Chr(13))
strPopUp.Append("//--></script>")
Response.Write(strPopUp.ToString)
 
In this line "window.open('', ""win"", strFeatures);"
try changing the second parameter to a unique window name for each popup. You'll have to get rid of ".focus();" because 2 windows will compete for focus and that won't work. Also you should adjust the TOP and LEFT so the windows tile.

Do you have to have 2 popups or could you show 2 messages in one popup?
 
You should know that "document.write()" has been deprecated.

Also, "Response.Write()" isn't really in the "spirit" of ASP.NET.

If I had to open several windows, I would create a JavaScript to do so. I would include this JavaScript via the Page.RegisterStartupScript() method.

For example, use a StringBuilder object. For each window you need to open, append the JavaScript code to do so.

Then, wrap the entire string in <script></script> tags, and pass the string to the Page via RegisterStartupScript.

If you need to set the contents of the window, don't use document.write(). Use the ".innerHTML" property of a control (such as a DIV) on the window's page.

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
Thanks Guys, I would try both the suggestions. Tgreer, I did try using registerstartupscript method, but as response.write, it was showing only the last popup and not both of them. I would let u know how it went in a while.
 
Brilliant guys!![bigsmile] it worked!! I made the change as suggested by stsuing and both windows opened. Well, its a requirement that if whatever number of messages have been posted in one minute duration, those many windows need to open on the client side, so as to make them aware that a new message has come up.[thumbsup2]

Regarding Using the ".innerHTML" property of a control (such as a DIV) on the window's page, I will work on it now that its opening new widnows as required:)
 
teclioness , I have a similar requirement. How do you set it up so that the popups occur at a specified interval/

thanks,

JIm
 
Hi jbenson001,

I have a datagrid in a page which is displaying all the messages. The page refreshes after 1 minute and in that I have put code to check against database if there is any new message posted since last ones.
 
OK, but my question is how do you refresh the page at a specified interval?

Thanks..
 
>>OK, but my question is how do you refresh the page at a specified interval

use javascript like so:
<script>
setTimeout("location.reload()",2000) // in milliseconds
</script>


or using META tags (Refresh attribute)...

Known is handfull, Unknown is worldfull
 
no problem...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top