Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help building javascript with StringBuilder

Posted on 2008-06-26
3
Medium Priority
?
627 Views
Last Modified: 2010-05-18
In my ASP.Net 1.1, VB.Net application, I am opening a modal popup window.
When the submit button in that window is clicked, I am trying to write some javascript
that will set the window.returnValue and kick off the __doPostBack of the parent
page.

So far, it goes so far as to force the parent page postback, but the __doPostBack
arguments I am passing are not being received in the parent page.  In the page load event,
I am checking the Request.Form("__EVENTTARGET") and Request.Form("__EVENTARGUMENT")
but they are blank.

This is my code:

            result = SavePDFsToDatabase(fileList)
            Dim script As StringBuilder = New StringBuilder

            script.Append(vbCrLf)
            script.Append("<script for=""window"" event=""onload"" language=""javascript"">")
            script.Append(vbCrLf)
            script.Append("window.returnValue=")
            script.Append(result.ToString)
            script.Append(";")
            script.Append(vbCrLf)
            script.Append("window.close();")
            script.Append(vbCrLf)
            script.Append("_doPostBack('RefreshData,window.returnValue');")  <==THESE VALUES ARE NOT MAKING INTO REQUEST.FORM FOR THE  PARENT PAGE.
            script.Append("</script>")

            RegisterClientScriptBlock("", script.ToString)

This is the Javascript being generated:

<script for="window" event="onload" language="javascript">
window.returnValue=1;
window.close();
_doPostBack('RefreshData,window.returnValue');</script>

Help!
Thanks.
0
Comment
Question by:JeffDrummond
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
orbulat earned 1000 total points
ID: 21881748
http://www.velocityreviews.com/forums/t76583-lose-state-information-when-using-dopostback-from-javascript.html

see if it helps, u may also have a look on the examples that overrides doPostBack

just a quick thought, how about using "RegisterStartupScript" instead of "RegisterClientScriptBlock"
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 1000 total points
ID: 21882023
When a showModalDialog runs, it does

var someVar = showModalDialog(....

and someVar is updated with returnValue when the window is closed
That is as far as I know all that happens unless asp.net generates more complex code for the parent window on the doPostBack
0
 

Author Comment

by:JeffDrummond
ID: 21916111
Thanks for your comments.  I have been able to get this to work.  My modal window.returnValue
does get passed back to the invoking Javascript in the parent page.  With that value I can
determine whether or not to use __doPostBack.  In my parent Page_Load event, I look for
the __EventTarget and __Event Argument values.  

In Javascript:

// Open window that allows user to add PDF files.
function OpenAddPDFWindow()
{
var rowsInserted = window.showModalDialog('AddPDFs.htm','','dialogWidth:640px;dialogHeight:510px');
if (rowsInserted > 0)
     {
      __doPostBack('RefreshData', rowsInserted);
     }
}

In Page_Load:

                '-- Check if this postback is the result of uploading a .pdf file.
                '-- Set the message label if so.
                '-- This postback is actually a __doPostBack in Javascript.
                Dim target As String = Request.Form("__EVENTTARGET")
                Dim rowsInserted As Integer

                Try
                    rowsInserted = Int32.Parse(Request.Form("__EVENTARGUMENT"))
                Catch ex As Exception
                    rowsInserted = 0
                End Try

                If target = "RefreshData" Then

                    If rowsInserted > 0 Then
                        Me.lbl_Message.Text = rowsInserted.ToString & " PDF file(s) saved successfully."
                    End If

                End If

                PopulateDatagrid()

If there is a better way of doing this, I would of course appreciate the advice.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question