Solved

showModalDialog returning value

Posted on 2008-10-17
5
2,538 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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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