Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

Help building javascript with StringBuilder

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
JeffDrummond
Asked:
JeffDrummond
2 Solutions
 
orbulatCommented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
JeffDrummondAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now