popup on Button Click and running server-side button_Click() code?

Discussion in 'ASP .Net' started by =?Utf-8?B?Vk1J?=, Oct 9, 2006.

  1. I have a LinkButton_search on my Page1.aspx that opens up a popup page called
    popup.aspx. I do this with LinkButton.Attributes.Add() on the Page_Load of
    Page1.aspx.
    How can I add server-side code to LinkButton_search_Click() so that the code
    in there runs before opening the popup window? The problem is that I fill a
    Session variable when I click on the button that will then be used in the
    Page_Load of my Popup window. So basically this is what I want:
    1) Add the "onclick" Attribute to the LinkButton (so it's a popup window)
    2) Run the LinkButton_search_Click(object sender, EventArgs e) to fill the
    Session variable
    3) Open popup.aspx as a popup window and in its Page_Load() use the Session
    variable that was filled in step 2.

    Any help is appreciated.
    Thanks
     
    =?Utf-8?B?Vk1J?=, Oct 9, 2006
    #1
    1. Advertising

  2. What you can do is -

    Write your Server side script on the clicked event. Also, build your
    javascript function in a string variable and then use the
    RegisterClientScript functionality to register and run the client script. You
    can google for RegisterClientScript and you should be able to get some
    examples for that.


    --
    Ameet Phadnis
    Sr. Technical Consultant
    e Tek Global Inc.
    ASP Alliance Author Page: http://aspalliance.com/author.aspx?uId=44260


    "VMI" wrote:

    > I have a LinkButton_search on my Page1.aspx that opens up a popup page called
    > popup.aspx. I do this with LinkButton.Attributes.Add() on the Page_Load of
    > Page1.aspx.
    > How can I add server-side code to LinkButton_search_Click() so that the code
    > in there runs before opening the popup window? The problem is that I fill a
    > Session variable when I click on the button that will then be used in the
    > Page_Load of my Popup window. So basically this is what I want:
    > 1) Add the "onclick" Attribute to the LinkButton (so it's a popup window)
    > 2) Run the LinkButton_search_Click(object sender, EventArgs e) to fill the
    > Session variable
    > 3) Open popup.aspx as a popup window and in its Page_Load() use the Session
    > variable that was filled in step 2.
    >
    > Any help is appreciated.
    > Thanks
     
    =?Utf-8?B?QW1lZXQgUGhhZG5pcyhlIFRlayBHbG9iYWwgSW5j, Oct 9, 2006
    #2
    1. Advertising

  3. Howdy,

    Quick example:

    -- BEGIN SEARCH PAGE --

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:LinkButton runat="server" ID="SearchButton" Text="Search"
    OnClick="SearchButton_Click"/>
    </div>
    </form>
    </body>
    </html>

    //code behind

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class SearchPage : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {
    DateTime date = DateTime.Now;
    Session["SearchVariable"] = date;

    Response.Write(date);

    RegisterPopupScript();
    }

    /// <summary>
    ///
    /// </summary>
    private void RegisterPopupScript()
    {
    Type type = this.GetType();

    if (ClientScript.IsStartupScriptRegistered(type, "PopupScript"))
    return;

    System.Text.StringBuilder script = new System.Text.StringBuilder();

    script.Append("<script language=\"javascript\"
    type=\"text/javascript\">\n");
    script.Append("//<!--\n");
    script.Append("window.open('popup.aspx', '_blank',
    'width=400,height=400');");
    script.Append("//-->\n");
    script.Append("</script>");

    ClientScript.RegisterStartupScript(type, "PopupScript", script.ToString());

    }
    }


    -- END SEARCH PAGE --

    -- BEGIN POPUP PAGE --

    // place label with ID="SearchResult"


    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class popup : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    SearchResult.Text = Convert.ToString(Session["SearchVariable"]);
    }
    }
    -- END POPUP PAGE --

    --

    Hope this helps

    Milosz Skalecki
    MCP, MCAD


    "VMI" wrote:

    > I have a LinkButton_search on my Page1.aspx that opens up a popup page called
    > popup.aspx. I do this with LinkButton.Attributes.Add() on the Page_Load of
    > Page1.aspx.
    > How can I add server-side code to LinkButton_search_Click() so that the code
    > in there runs before opening the popup window? The problem is that I fill a
    > Session variable when I click on the button that will then be used in the
    > Page_Load of my Popup window. So basically this is what I want:
    > 1) Add the "onclick" Attribute to the LinkButton (so it's a popup window)
    > 2) Run the LinkButton_search_Click(object sender, EventArgs e) to fill the
    > Session variable
    > 3) Open popup.aspx as a popup window and in its Page_Load() use the Session
    > variable that was filled in step 2.
    >
    > Any help is appreciated.
    > Thanks
     
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tp?=, Oct 9, 2006
    #3
    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. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=
    Replies:
    2
    Views:
    6,562
    rick74
    May 27, 2008
  2. =?Utf-8?B?fkp+?=
    Replies:
    3
    Views:
    4,613
    John Timney \(Microsoft MVP\)
    Jun 8, 2004
  3. Joey
    Replies:
    1
    Views:
    818
    =?Utf-8?B?aGVpbg==?=
    Jan 3, 2006
  4. Amy
    Replies:
    0
    Views:
    1,038
  5. Aymer
    Replies:
    1
    Views:
    404
    Alvin Bruney
    Sep 19, 2003
Loading...

Share This Page