showModalDialog with an ASP page

Discussion in 'ASP .Net' started by Ralf, Nov 21, 2006.

  1. Ralf

    Ralf Guest

    Here is my scenerio and what I am doing. I am open to other ways of
    doing this is it makes sense. I have a cell withing a row within a
    datagrid. When this cell is clicked (its a date field), I want a
    calendar to pop up to change the date. So, I had to added an onclick
    event to the cell, which runs a javascript function when it the click
    happens. The javascript function does the showModalDialog to open the
    Calendar.aspx page and pass in the date field that was in the cell to
    prepopulate the calendar control on the new page.

    window.showModalDialog('Calendar.aspx',info); //info had the date to
    pre-populate

    On the new page, how do I get the pre-populated date to my code behind?
    I added a HTML button to the modal page and wrote the script to click
    the button to activate the event to get into my code behind. But, how
    do I get the value 'info' that was passed over to open the dialog
    Calendar window? I read where it said to use window.dialogArguments,
    but I couldn't get that to work at all, it doesn't recognize it. And
    since that is in the javascript, how would I get it to the code behind?

    Any insight is appreciated
    Ralf, Nov 21, 2006
    #1
    1. Advertising

  2. hi,
    u could use this basic opensource component or you could do methods by your
    self.
    http://www.codeproject.com/aspnet/WebModalAnchor.asp

    if you want to learn how this component do this job and what you need to do
    for making your own modalwindow reed the thinks that i explained to you.

    first of all. i want to explain you a silly think that u know about the
    modelwindows.
    if you open an aspx page which could be posted and reloaded.
    the model window lost its properties.
    i mean when u refresh the model windows it goes and comes back as a normal
    popup window.
    you could fix this problem by opening an iframe instead of opening the aspx
    page.
    like open an iframe page which contains your aspx page.

    and now your problem solution.
    there is components which does the job which you want. but i get problems
    with them so i create my owns and happy with them.
    this is the function which you should call from the cell click.
    you could create your own argument list.

    function fnOpen()
    {
    var myarguments=new Array();
    myarguments[0]=window.self;
    myarguments[1]="CID";
    myarguments[2]="calender.aspx";
    myarguments[3]=650;//width
    myarguments[4]=400;//height
    var width =myarguments[3];
    var height =myarguments[4];
    var
    cur=window.showModalDialog("ModalblankIframe.htm",myarguments,"status:eek:n;
    center:eek:n;
    help:eek:ff;resizable:yes;dialogHeight:"+height+"px;dialogWidth:"+width+"px;scroll:yes;");

    }

    // and this is for when the modal window sends the value . it calls this
    method.
    function setParentReturnValue(returnvalue)
    {
    //this below line is for clearing and not checking the page validators ex
    required page validator etc..
    if (typeof(Page_Validators) != "undefined")
    {
    Page_Validators=new Array();//clearing the validator array
    }

    //i put an hidden value holder to the page. <input type=hidden id=hdnvalue
    runat=server>
    document.getEllementById('<%=hdnvalue.ClientID.Trim()%>').value=returnvalue;

    // and i also put an button with style display:none to the page for
    submiting the page to this button click event.
    //<asp:button id-buttonhidden runat=server style="display:none;"></asp:button>

    document.getElementById('<%=buttonHidden.ClientID.Trim()%>').click();
    // now you could do every server side operations at this button click event
    if you need it.

    }

    //at the iframe
    //which i told you why i use iframe at the begining of my post.

    <script language="javascript">
    var myarguments=null;

    function InitFrame(){
    myarguments =window.dialogArguments;
    document.getElementById('frContainer').src=myarguments[2]+"?key="+myarguments[1];
    }
    </script>
    </head>
    <body onload="InitFrame();">
    <form name="form1" ID="Form1">
    <iframe id="frContainer" src="" frameborder="0" height="100%" width="100%">
    </iframe>
    </form>
    </body>
    </html>

    // and now at your calender.aspx page
    when y gona close and want to submit the data to parent
    //call the closeandsubmit method with page.registerstartupscript

    <script>
    function CloseAndSubmit()
    {
    //hdnreturnvalue is the value which u set at the code behind which u want to
    submit to parent.
    window.top.myarguments[0].setParentReturnValue(document.getElementById('<%=hdnreturnvalue.ClientID%>').value);
    self.close();
    }
    </script>

    --
    Esref DURNA
    Software Engineer

    www.esrefdurna.com
    An Asp.Net , C# Turkish Cypriot lover


    "Ralf" wrote:

    > Here is my scenerio and what I am doing. I am open to other ways of
    > doing this is it makes sense. I have a cell withing a row within a
    > datagrid. When this cell is clicked (its a date field), I want a
    > calendar to pop up to change the date. So, I had to added an onclick
    > event to the cell, which runs a javascript function when it the click
    > happens. The javascript function does the showModalDialog to open the
    > Calendar.aspx page and pass in the date field that was in the cell to
    > prepopulate the calendar control on the new page.
    >
    > window.showModalDialog('Calendar.aspx',info); //info had the date to
    > pre-populate
    >
    > On the new page, how do I get the pre-populated date to my code behind?
    > I added a HTML button to the modal page and wrote the script to click
    > the button to activate the event to get into my code behind. But, how
    > do I get the value 'info' that was passed over to open the dialog
    > Calendar window? I read where it said to use window.dialogArguments,
    > but I couldn't get that to work at all, it doesn't recognize it. And
    > since that is in the javascript, how would I get it to the code behind?
    >
    > Any insight is appreciated
    >
    >
    =?Utf-8?B?RXNyZWYgRFVSTkE=?=, Nov 21, 2006
    #2
    1. Advertising

  3. The easiest way is to add the info to the url as query parameter, like
    Calendar.aspx?info=xxx, and access it from code-behind as
    Request.QueryString["info"]


    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Ralf" <> wrote in message
    news:...
    > Here is my scenerio and what I am doing. I am open to other ways of
    > doing this is it makes sense. I have a cell withing a row within a
    > datagrid. When this cell is clicked (its a date field), I want a
    > calendar to pop up to change the date. So, I had to added an onclick
    > event to the cell, which runs a javascript function when it the click
    > happens. The javascript function does the showModalDialog to open the
    > Calendar.aspx page and pass in the date field that was in the cell to
    > prepopulate the calendar control on the new page.
    >
    > window.showModalDialog('Calendar.aspx',info); //info had the date to
    > pre-populate
    >
    > On the new page, how do I get the pre-populated date to my code behind?
    > I added a HTML button to the modal page and wrote the script to click
    > the button to activate the event to get into my code behind. But, how
    > do I get the value 'info' that was passed over to open the dialog
    > Calendar window? I read where it said to use window.dialogArguments,
    > but I couldn't get that to work at all, it doesn't recognize it. And
    > since that is in the javascript, how would I get it to the code behind?
    >
    > Any insight is appreciated
    >
    Eliyahu Goldin, Nov 22, 2006
    #3
  4. Ralf

    Ralf Guest

    OK, I used the QueryString and got the value over no problem.
    My new problem is passing the intended value back to the parent page. I
    did this on another page, but it was a regular page and not a modal
    page. The same thing doesn't work. Before, I was doing

    Response.Write("<script>window.opener.parent.__doPostBack('tbControl','"
    + ddlIntGrpName.SelectedValue + "')</script>")

    Which was sending the post back like it was from a control named
    tbControl, so I would capture it and get the value that was passed back
    with it. Well, with a modal window, window.opener is not longer valid.
    This is how I opened the modal window from my parent window. This is
    in the jscript, I added this function to the onclick event. It works
    great.

    <script>function CellClick(info)
    {
    var changedDate = window.showModalDialog('Calendar.aspx?info=' +
    info);
    }
    </script>

    The was this is setup with changedDate being the return, how do I pass
    it back to it. Any ideas are appreciated!!
    Ralf, Dec 14, 2006
    #4
  5. Ralf

    Ralf Guest

    got it.
    returnValue='xxxx' in jscript
    Ralf, Dec 14, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sarah
    Replies:
    2
    Views:
    2,222
  2. Replies:
    1
    Views:
    8,064
    gnubslayer
    Jun 1, 2007
  3. Replies:
    0
    Views:
    632
  4. =?Utf-8?B?QXhmb3Jk?=

    showModalDialog and master page

    =?Utf-8?B?QXhmb3Jk?=, May 15, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    628
    =?Utf-8?B?QXhmb3Jk?=
    Jun 2, 2006
  5. Jonathan
    Replies:
    0
    Views:
    189
    Jonathan
    Jul 19, 2004
Loading...

Share This Page