Open new browser window on server side button click

Discussion in 'ASP .Net' started by shil, Nov 2, 2005.

  1. shil

    shil Guest

    I have a server side button that needs to do some preperation and
    afterwards, if everything goes well, open a new browser with a specific
    url.

    I know how to execute javascript from a server side control, adding the
    javascript to the attributes. I need to open the browser window AFTER
    the code behind event is finished.

    For example I have two text boxes on the form, whose values I want to
    send as parameters to the URL that I want to open on server side button
    click. I wrote code to add attributes to that button Onclick. What
    happens is when I click on the button, it is adding attribute to that
    button. The second click is opening the new browser. But I want to open
    the new browser on first click.

    Is there any way to accomplish this?

    Thanks,
    Shil.
     
    shil, Nov 2, 2005
    #1
    1. Advertising

  2. Hi Shil,

    If i have understood your problem correctly, this is how you can do it,
    Add the attributes for the button on the page load.

    page_load()
    button1.attributes.add("abcd","abcd");

    now when you click the button, call the open method of the Javascript by
    passing a URL along with the values in the text box as query string.

    something like this.
    button1_click()
    Response.write(<script>window.open('pass the url with Query string
    values')</string>

    This will open a new window, you can also set the size and all features of
    the new window exactly the way you do with the window.open.

    Hope this was helpful to you.

    Thanks,
    --
    Kannan.V
    Home : http://www.kannanv.com
    Blog : http://kannanv.blogspot.com
    Web : http://www.DotnetLounge.net

    "Any one who has never made a mistake has never tried anything new" - Einstein


    "shil" wrote:

    > I have a server side button that needs to do some preperation and
    > afterwards, if everything goes well, open a new browser with a specific
    > url.
    >
    > I know how to execute javascript from a server side control, adding the
    > javascript to the attributes. I need to open the browser window AFTER
    > the code behind event is finished.
    >
    > For example I have two text boxes on the form, whose values I want to
    > send as parameters to the URL that I want to open on server side button
    > click. I wrote code to add attributes to that button Onclick. What
    > happens is when I click on the button, it is adding attribute to that
    > button. The second click is opening the new browser. But I want to open
    > the new browser on first click.
    >
    > Is there any way to accomplish this?
    >
    > Thanks,
    > Shil.
    >
    >
     
    =?Utf-8?B?S2FubmFuLlYgW01DU0QubmV0XQ==?=, Nov 2, 2005
    #2
    1. Advertising

  3. shil,

    you can use RegisterStartUpScript to call the script to open winodw on page
    start up..

    Sample code is like below .. add this code in button click event in code
    behind

    string jscript = ""<script>";
    jscript += "winodw.open('yoururl.aspx?text1="+ TextBox1.Text + "&text2=" +
    TextBox2.Text + "')"
    jscript += "</script>";
    Page.RegisterStartUpScript("open", jscript );


    HTH

    "shil" wrote:

    > I have a server side button that needs to do some preperation and
    > afterwards, if everything goes well, open a new browser with a specific
    > url.
    >
    > I know how to execute javascript from a server side control, adding the
    > javascript to the attributes. I need to open the browser window AFTER
    > the code behind event is finished.
    >
    > For example I have two text boxes on the form, whose values I want to
    > send as parameters to the URL that I want to open on server side button
    > click. I wrote code to add attributes to that button Onclick. What
    > happens is when I click on the button, it is adding attribute to that
    > button. The second click is opening the new browser. But I want to open
    > the new browser on first click.
    >
    > Is there any way to accomplish this?
    >
    > Thanks,
    > Shil.
    >
    >
     
    =?Utf-8?B?U3JlZWppdGggUmFt?=, Nov 2, 2005
    #3
  4. shil

    shil Guest

    That is exactly what I was looking for. Thank you very much Kannan.
    Worked great!!
     
    shil, Nov 2, 2005
    #4
  5. shil

    Ken Varn Guest

    I have done this by registering a using a placeholder control in the web
    page for script that I add only when postback is performed.

    In the server side button control event handler, place the script into the
    placeholder control on the server side. Thus, when the page posts back, the
    JavaScript can execute to open a new window. If you don't want the script
    to be remembered on each postback, then set EnableViewState = false for the
    placeholder control.


    --
    -----------------------------------
    Ken Varn
    Senior Software Engineer
    Diebold Inc.

    EmailID = varnk
    Domain = Diebold.com
    -----------------------------------
    "shil" <> wrote in message
    news:...
    > I have a server side button that needs to do some preperation and
    > afterwards, if everything goes well, open a new browser with a specific
    > url.
    >
    > I know how to execute javascript from a server side control, adding the
    > javascript to the attributes. I need to open the browser window AFTER
    > the code behind event is finished.
    >
    > For example I have two text boxes on the form, whose values I want to
    > send as parameters to the URL that I want to open on server side button
    > click. I wrote code to add attributes to that button Onclick. What
    > happens is when I click on the button, it is adding attribute to that
    > button. The second click is opening the new browser. But I want to open
    > the new browser on first click.
    >
    > Is there any way to accomplish this?
    >
    > Thanks,
    > Shil.
    >
     
    Ken Varn, Nov 2, 2005
    #5
  6. shil

    Bruce Barker Guest

    of course popup blockers (xp-sp2), prevent this code from working.

    -- bruce (sqlwork.com)


    "shil" <> wrote in message
    news:...
    > That is exactly what I was looking for. Thank you very much Kannan.
    > Worked great!!
    >
     
    Bruce Barker, Nov 2, 2005
    #6
  7. shil

    shil Guest

    I agree with you Bruce.
    But is there any other way to open a new window with out using
    Javascript?

    Thanks,
    Shil.
     
    shil, Nov 2, 2005
    #7
    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. Mathew George
    Replies:
    1
    Views:
    2,371
  2. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
    Replies:
    2
    Views:
    6,496
    rick74
    May 27, 2008
  3. =?Utf-8?B?Tm92aWNl?=
    Replies:
    2
    Views:
    6,665
    Alan Ferrandiz Langley
    Jun 9, 2004
  4. Aymer
    Replies:
    1
    Views:
    389
    Alvin Bruney
    Sep 19, 2003
  5. Gordon
    Replies:
    3
    Views:
    310
    Steven Burn
    Apr 16, 2004
Loading...

Share This Page