Results 1 to 9 of 9

Thread: [RESOLVED] [vs2005] center child window

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Resolved [RESOLVED] [vs2005] center child window

    hi,

    im opening a child window by injecting code through gridview rowdatabound.
    and also at the same time i wanted to center the child window through the function leftmargin(); but the function does not returning any values when object is triggered.


    Code:
    DirectCast(e.Row.FindControl("pb_editImage"), Image).Attributes.Add("onclick", "window.open('popup_window.aspx?id=" & e.Row.DataItem("id") & "','win_title','menubar=no,status=no,toolbar=no,scrollbars=no,width=540px,height=400px, left=leftmargin();').focus();")
    Code:
    <script type="text/javascript" >
    function leftmargin(){
     var a ;
     a  = (screen.width  - width)/2; 
    
     return a;
    }
    </script>
    Learn something new every .001 second.

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: [vs2005] center child window

    You're putting in the call to leftmargin() as part of a string. To have it called as a function, it needs to be outside of the string context:
    Code:
    DirectCast(e.Row.FindControl("pb_editImage"), Image).Attributes.Add("onclick", "window.open('popup_window.aspx?id=" & e.Row.DataItem("id") & "','win_title','menubar=no,status=no,toolbar=no,scrollbars=no,width=540px,height=400px, left='+leftmargin()).focus();")
    Also make sure that the "width" variable in your function has a value.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [vs2005] center child window

    hey,

    the same did not work and it return an error expected ")". heres the markup.

    Code:
    onclick="window.open('performance_bond.aspx?id=5','win_title','menubar=no,status=no,toolbar=no,scrollbars=no,width=540px,height=450px, left='+leftmargin();).focus();"
    Learn something new every .001 second.

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [vs2005] center child window

    if you look closely, Samba's code does not have the semi-colon you added to leftmargin(). a semi-colon in JavaScript is a line terminator, and you're not terminating that line until you call the focus() method.
    Like Archer? Check out some Sterling Archer quotes.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [vs2005] center child window

    hey,

    I remember doing that but it also return an error message WIDTH is undefined. But the markup includes the width property.

    Code:
    onclick="window.open('performance_bond.aspx?id=5','win_title','menubar=no,status=no,toolbar=no,scrollbars=no,width=540px,height=450px, left='+leftmargin()).focus();"
    Learn something new every .001 second.

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [vs2005] center child window

    use just numbers; get rid of the "px."
    Like Archer? Check out some Sterling Archer quotes.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [vs2005] center child window

    Quote Originally Posted by kows View Post
    use just numbers; get rid of the "px."
    I already do that,regardless of having "px" or not suffix in height and width it works fine. Only that error comes in when I derived left value from function.

    And that did not fix the error of undefined width as well.

    Thanks.
    Learn something new every .001 second.

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: [vs2005] center child window

    Oh. In your function, you never define width, just like Samba said:

    Quote Originally Posted by SambaNeko View Post
    Also make sure that the "width" variable in your function has a value.
    Like Archer? Check out some Sterling Archer quotes.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [vs2005] center child window

    Quote Originally Posted by kows View Post
    Oh. In your function, you never define width, just like Samba said:
    OMG I totally miss that.
    It seems to work fine now with a fix value in width function.
    I did not realize width is not a reserve keyword in js.
    Learn something new every .001 second.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width