Open a new window and set session variable?

Discussion in 'ASP .Net' started by rockdale, Jul 3, 2006.

  1. rockdale

    rockdale Guest

    Hi, all:

    I have a linkbutton and I use javascript to open another webpage in a
    new window. I also want to set my session variable value when this
    linkbutton get clicked. These session variable is used in the the
    webpage that in the new window. I do not want pass these variables as
    parameters to the web page. Can I let the linkbutton execute postback
    to set the session variable's value and also execute client javascript
    to open a new window? I tried but get no luck. Or you have a better
    idea to achieve this?


    following is my code
    <script language="javascript">
    function NewWindow(strUrl){
    var win = window.open(strUrl, null, 'height=600,width=1024,status=no,
    toolbar=no,menubar=no,location=no');
    }
    </script>
    <asp:linkbutton id="lbnPrint" runat="server" CssClass="NormalLinkSmall"
    >Print</asp:linkbutton>


    code behind
    lbnPrint.Attributes.Add("onClick","NewWindow('print.aspx)");





    Thanks a lot
    -rockdale
     
    rockdale, Jul 3, 2006
    #1
    1. Advertising

  2. If you open the new page from client script in the button, you can't set
    the session variable before the new page loads.

    You have to first make the postback to set the session variable and
    output the client script that opens the new page. Then the new page will
    open when the page loads after postback.

    rockdale wrote:
    > Hi, all:
    >
    > I have a linkbutton and I use javascript to open another webpage in a
    > new window. I also want to set my session variable value when this
    > linkbutton get clicked. These session variable is used in the the
    > webpage that in the new window. I do not want pass these variables as
    > parameters to the web page. Can I let the linkbutton execute postback
    > to set the session variable's value and also execute client javascript
    > to open a new window? I tried but get no luck. Or you have a better
    > idea to achieve this?
    >
    >
    > following is my code
    > <script language="javascript">
    > function NewWindow(strUrl){
    > var win = window.open(strUrl, null, 'height=600,width=1024,status=no,
    > toolbar=no,menubar=no,location=no');
    > }
    > </script>
    > <asp:linkbutton id="lbnPrint" runat="server" CssClass="NormalLinkSmall"
    >> Print</asp:linkbutton>

    >
    > code behind
    > lbnPrint.Attributes.Add("onClick","NewWindow('print.aspx)");
    >
    >
    >
    >
    >
    > Thanks a lot
    > -rockdale
    >
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Jul 4, 2006
    #2
    1. Advertising

  3. rockdale

    rockdale Guest

    I am sorry, but how can I output the client script? using
    response.write? any code sample?

    Thanks a lot

    Göran Andersson wrote:
    > If you open the new page from client script in the button, you can't set
    > the session variable before the new page loads.
    >
    > You have to first make the postback to set the session variable and
    > output the client script that opens the new page. Then the new page will
    > open when the page loads after postback.
    >
    > rockdale wrote:
    > > Hi, all:
    > >
    > > I have a linkbutton and I use javascript to open another webpage in a
    > > new window. I also want to set my session variable value when this
    > > linkbutton get clicked. These session variable is used in the the
    > > webpage that in the new window. I do not want pass these variables as
    > > parameters to the web page. Can I let the linkbutton execute postback
    > > to set the session variable's value and also execute client javascript
    > > to open a new window? I tried but get no luck. Or you have a better
    > > idea to achieve this?
    > >
    > >
    > > following is my code
    > > <script language="javascript">
    > > function NewWindow(strUrl){
    > > var win = window.open(strUrl, null, 'height=600,width=1024,status=no,
    > > toolbar=no,menubar=no,location=no');
    > > }
    > > </script>
    > > <asp:linkbutton id="lbnPrint" runat="server" CssClass="NormalLinkSmall"
    > >> Print</asp:linkbutton>

    > >
    > > code behind
    > > lbnPrint.Attributes.Add("onClick","NewWindow('print.aspx)");
    > >
    > >
    > >
    > >
    > >
    > > Thanks a lot
    > > -rockdale
    > >
     
    rockdale, Jul 4, 2006
    #3
  4. Use the RegisterClientScript method.

    rockdale wrote:
    > I am sorry, but how can I output the client script? using
    > response.write? any code sample?
    >
    > Thanks a lot
    >
    > Göran Andersson wrote:
    >> If you open the new page from client script in the button, you can't set
    >> the session variable before the new page loads.
    >>
    >> You have to first make the postback to set the session variable and
    >> output the client script that opens the new page. Then the new page will
    >> open when the page loads after postback.
    >>
    >> rockdale wrote:
    >>> Hi, all:
    >>>
    >>> I have a linkbutton and I use javascript to open another webpage in a
    >>> new window. I also want to set my session variable value when this
    >>> linkbutton get clicked. These session variable is used in the the
    >>> webpage that in the new window. I do not want pass these variables as
    >>> parameters to the web page. Can I let the linkbutton execute postback
    >>> to set the session variable's value and also execute client javascript
    >>> to open a new window? I tried but get no luck. Or you have a better
    >>> idea to achieve this?
    >>>
    >>>
    >>> following is my code
    >>> <script language="javascript">
    >>> function NewWindow(strUrl){
    >>> var win = window.open(strUrl, null, 'height=600,width=1024,status=no,
    >>> toolbar=no,menubar=no,location=no');
    >>> }
    >>> </script>
    >>> <asp:linkbutton id="lbnPrint" runat="server" CssClass="NormalLinkSmall"
    >>>> Print</asp:linkbutton>
    >>> code behind
    >>> lbnPrint.Attributes.Add("onClick","NewWindow('print.aspx)");
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> Thanks a lot
    >>> -rockdale
    >>>

    >
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, Jul 4, 2006
    #4
  5. rockdale

    rockdale Guest

    Hi, Goran:

    Can you be more specific?
    I still could not get it work. If replace window.open with alert, it
    works.

    following is my code
    private void ButtonPrintAll_Click(object sender, System.EventArgs e)
    {
    Session["VAR_1"] = ###;
    Session["VAR_2"] = ###;
    String js = BuildOpenWindowsJavaScript();
    Page.RegisterClientScriptBlock("OpenWindow", js);
    }


    private String BuildOpenWindowsJavaScript(){
    System.Text.StringBuilder js = new System.Text.StringBuilder ();
    js.Append("<script language=\"javascript\">");
    js.Append("\n");
    //js.Append("alert(\"this is a test\");");
    js.Append ("window.open(\"www.google.com\");");
    js.Append ("</script>");
    return js.ToString ();
    }



    Göran Andersson wrote:
    > Use the RegisterClientScript method.
    >
    > rockdale wrote:
    > > I am sorry, but how can I output the client script? using
    > > response.write? any code sample?
    > >
    > > Thanks a lot
    > >
    > > Göran Andersson wrote:
    > >> If you open the new page from client script in the button, you can't set
    > >> the session variable before the new page loads.
    > >>
    > >> You have to first make the postback to set the session variable and
    > >> output the client script that opens the new page. Then the new page will
    > >> open when the page loads after postback.
    > >>
    > >> rockdale wrote:
    > >>> Hi, all:
    > >>>
    > >>> I have a linkbutton and I use javascript to open another webpage in a
    > >>> new window. I also want to set my session variable value when this
    > >>> linkbutton get clicked. These session variable is used in the the
    > >>> webpage that in the new window. I do not want pass these variables as
    > >>> parameters to the web page. Can I let the linkbutton execute postback
    > >>> to set the session variable's value and also execute client javascript
    > >>> to open a new window? I tried but get no luck. Or you have a better
    > >>> idea to achieve this?
    > >>>
    > >>>
    > >>> following is my code
    > >>> <script language="javascript">
    > >>> function NewWindow(strUrl){
    > >>> var win = window.open(strUrl, null, 'height=600,width=1024,status=no,
    > >>> toolbar=no,menubar=no,location=no');
    > >>> }
    > >>> </script>
    > >>> <asp:linkbutton id="lbnPrint" runat="server" CssClass="NormalLinkSmall"
    > >>>> Print</asp:linkbutton>
    > >>> code behind
    > >>> lbnPrint.Attributes.Add("onClick","NewWindow('print.aspx)");
    > >>>
    > >>>
    > >>>
    > >>>
    > >>>
    > >>> Thanks a lot
    > >>> -rockdale
    > >>>

    > >
     
    rockdale, Jul 5, 2006
    #5
  6. rockdale

    rockdale Guest

    Oops, just found out that my IE does not allow popups.
    Thanks


    rockdale wrote:
    > Hi, Goran:
    >
    > Can you be more specific?
    > I still could not get it work. If replace window.open with alert, it
    > works.
    >
    > following is my code
    > private void ButtonPrintAll_Click(object sender, System.EventArgs e)
    > {
    > Session["VAR_1"] = ###;
    > Session["VAR_2"] = ###;
    > String js = BuildOpenWindowsJavaScript();
    > Page.RegisterClientScriptBlock("OpenWindow", js);
    > }
    >
    >
    > private String BuildOpenWindowsJavaScript(){
    > System.Text.StringBuilder js = new System.Text.StringBuilder ();
    > js.Append("<script language=\"javascript\">");
    > js.Append("\n");
    > //js.Append("alert(\"this is a test\");");
    > js.Append ("window.open(\"www.google.com\");");
    > js.Append ("</script>");
    > return js.ToString ();
    > }
    >
    >
    >
    > Göran Andersson wrote:
    > > Use the RegisterClientScript method.
    > >
    > > rockdale wrote:
    > > > I am sorry, but how can I output the client script? using
    > > > response.write? any code sample?
    > > >
    > > > Thanks a lot
    > > >
    > > > Göran Andersson wrote:
    > > >> If you open the new page from client script in the button, you can'tset
    > > >> the session variable before the new page loads.
    > > >>
    > > >> You have to first make the postback to set the session variable and
    > > >> output the client script that opens the new page. Then the new page will
    > > >> open when the page loads after postback.
    > > >>
    > > >> rockdale wrote:
    > > >>> Hi, all:
    > > >>>
    > > >>> I have a linkbutton and I use javascript to open another webpage ina
    > > >>> new window. I also want to set my session variable value when this
    > > >>> linkbutton get clicked. These session variable is used in the the
    > > >>> webpage that in the new window. I do not want pass these variables as
    > > >>> parameters to the web page. Can I let the linkbutton execute postback
    > > >>> to set the session variable's value and also execute client javascript
    > > >>> to open a new window? I tried but get no luck. Or you have a better
    > > >>> idea to achieve this?
    > > >>>
    > > >>>
    > > >>> following is my code
    > > >>> <script language="javascript">
    > > >>> function NewWindow(strUrl){
    > > >>> var win = window.open(strUrl, null, 'height=600,width=1024,status=no,
    > > >>> toolbar=no,menubar=no,location=no');
    > > >>> }
    > > >>> </script>
    > > >>> <asp:linkbutton id="lbnPrint" runat="server" CssClass="NormalLinkSmall"
    > > >>>> Print</asp:linkbutton>
    > > >>> code behind
    > > >>> lbnPrint.Attributes.Add("onClick","NewWindow('print.aspx)");
    > > >>>
    > > >>>
    > > >>>
    > > >>>
    > > >>>
    > > >>> Thanks a lot
    > > >>> -rockdale
    > > >>>
    > > >
     
    rockdale, Jul 5, 2006
    #6
    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. Jazzis
    Replies:
    4
    Views:
    196
    Jazzis
    Sep 26, 2003
  2. raj
    Replies:
    8
    Views:
    588
    J. Baute
    Apr 9, 2004
  3. Gordon
    Replies:
    3
    Views:
    324
    Steven Burn
    Apr 16, 2004
  4. raj
    Replies:
    0
    Views:
    201
  5. PC HUA
    Replies:
    2
    Views:
    436
    PC HUA
    May 19, 2004
Loading...

Share This Page