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

x
?
Solved

showModalDialog returning value

Posted on 2008-10-17
5
Medium Priority
?
2,557 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 1500 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

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