Solved

showModalDialog returning value

Posted on 2008-10-17
5
2,532 Views
Last Modified: 2013-11-07
I am developing a web application with asp.net, vb.net and ajax extensions.

I am trying to implement a modal dialog, where the user can choose Accept or Cancel an action, returning (0-Calcel or 1-Accept) like a mesagebox function, as it can be called during codebehind process, that mean not through clicking a button.

But I have a problem, using the RegisterStartupScript works in this way:
Protected Function callPage() as Boolean
Dim resp as boolean = False
Dim pagName As String = "" 'page to call as modal
Dim size As String = ""
Dim script As String = ""
Dim txt As String = "Do you want delete records?"
pagName = "MsgBox.aspx?text=" & txt
size = "status:no;dialogWidth:300px;dialogHeight:120px;dialogHide:false;help:no;scroll:yes;resizable:no;"
script = "<script language='javascript' > window.showModalDialog('" & pagName & "', 'MessageBox', '" & size & "'); </script>"
UI.ScriptManager.RegisterStartupScript(Me, Me.GetType, "Respuesta", script, False)
End Sub

When the function is called a modal window appear (msgbox.aspx).

But need to catch the answer given for the user from the modal window, so If I modify the function:

Protected Function callPage() as Boolean
Dim resp as boolean = False
Dim pagName As String = "" 'page to call as modal
Dim size As String = ""
Dim script As String = ""
Dim txt As String = "Do you want delete records?"
pagName = "MsgBox.aspx?text=" & txt
size = "status:no;dialogWidth:300px;dialogHeight:120px;dialogHide:false;help:no;scroll:yes;resizable:no;"
script = "<script language='javascript' > var value= window.showModalDialog('" & pagName & "', 'Respuesta', '" & size & " ');  " & _
" document.getElementById(" & Chr(34) & "ctl00_ContentPlaceHolder1_Respuesta" & Chr(34) & ").value=value; " & _
" If (document.getElementById(" & Chr(34) & "ctl00_ContentPlaceHolder1_Respuesta" & Chr(34) & ").value==1 " & _
" {" & _
" <%= PostBackConfirm %>" & _
"}</script>"
UI.ScriptManager.RegisterStartupScript(Me, Me.GetType, "Respuesta", script, False)
End Sub

The idea is to catch in a postback the answer from user, buth with the fuction modified any happens, that mean the modal window is not showed.

What is wrong, can any body helpme or give an example, I don't know much about script (vb or js) code.

Thanks in advance

0
Comment
Question by:aslyas
[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
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
Christopher Kile earned 500 total points
ID: 22743738
This article gives an excellent example of how to return values from a modal dialog window (I believe it should also work for the modeless version, as well):

http://p2p.wrox.com/topic.asp?TOPIC_ID=27848

Once you've set up your dialog with the terminate() function as described in this example, the value is returned and can be stored in any variable you assign.  I suggest being VERY careful about assuming implicit conversions (I note the comparison with an integer value of one in your non-working code as being an example not to follow).  Also, you shouldn't be calling server functions from Javascript except to assign values to be used in the initial generation of the page.  Most commonly, if one wanted to pass the value returned by a modal dialog back to the server, one would assigned it to a server control (any HTML or ASP control with runat=server) then force the document to submit itself (e.g. document.forms[0].submit(); in Javascript).  Once your server code receives the postback, one can check the value of the server control and decide what to do from there.  Do you understand this?  Does it make sense?

0
 

Author Comment

by:aslyas
ID: 22763251
I tryied to apply the example to my code.
In parent window I am defining:
<script type ="text/javascript">    
   
    function open(pag,name,size)
    {
        var Return;
        Return = window.showModalDialog(pag,name,size);
        document.getElementById("Respuesta").value = Return.Respuesta        
    }
</script>
Where "Respuesta" is a hidden field
<asp:HiddenField ID="Respuesta" runat ="server" />
It is being called in this way:

        Dim pagName As String = ""
        Dim size As String = ""
        Dim script As String = ""
        Dim txt As String = "Desea eliminar los registros del mecanismo de daño: XYZ?"
        pagName = "MsgBox.aspx?text=" & txt
        size= "status:no;dialogWidth:300px;dialogHeight:120px;dialogHide:false;help:no;scroll:yes;resizable:no;"
               script = "<script language='javascript' > open('" & pagName & "', 'MsgBox', '" & size & "'); </script>"

        UI.ScriptManager.RegisterStartupScript(Me, Me.GetType, "Respuesta", script, False)

When that code is executed a script error appear, (expected identifier)
The code in modal window is:

       function close()
        {
            var vReturnValue = new object();
            vReturnValue.Respuesta = 0;
            window.return = vReturnValue;
            window.close;
        }
       function Ok()
        {
            var vReturnValue = new object();
            vReturnValue.Respuesta = 1;
            window.return = vReturnValue;
            window.close;
        }
And I am adding in page_load this:
        cmdAceptar.Attributes.Add("onclick", "Ok()")
        cmdCancelar.Attributes.Add("onclick", "close()")

Is something missing?

How can I catch the value?

Thanks for your help.
0
 

Author Comment

by:aslyas
ID: 22771452
Finally I got my goal.
I don't know why with object Return, it did not work I had  use of the hidden field in the result.
Code in parent page
   function open2(pag,name,size)
    {
        var Return = new Object();
        Return.Respuesta= window.showModalDialog(pag,name,size);        
        document.getElementById("Respuesta").value = Return.Respuesta;
        alert("Back... " + document.getElementById("Respuesta").value);
        if (document.getElementById("Respuesta").value==1)
        {
            alert("Enter to post...");
            <%= PostBackResp %>
        }        
    }
I am calling a postback to execute some code depending of the user seleccion in modal page.


And in the final code in modal page was:
 function Close()
        {
            var vReturnValue = new Object();
            vReturnValue.Respuesta = 0;            
            window.returnValue = vReturnValue.Respuesta;
            window.close();
        }
       
       function Ok()
        {
            var vReturnValue = new Object();
            vReturnValue.Respuesta = 1;            
            window.returnValue = vReturnValue.Respuesta;
            window.close();          
        }

Thanks a lot cpkilekofp
0
 

Author Closing Comment

by:aslyas
ID: 31507225
I give the points since gave me the direction.
0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 22771622
Sorry for my delayed response; I hadn't had a chance to test your code today.  Your solution is exactly what I've used in child forms before, though, and if I hadn't been hip deep in alligators today I'd probably have remembered to suggest it to you LOL.  Glad to help :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AJAx/JQuery/JSON Error 3 38
vb.net dbnull syntax 1 56
NOT having JQuery DataTable Columns Sort 7 35
Script to transfer files from web server to sharePoint server 3 33
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

734 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