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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VMI

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

    I have a LinkButton_sear ch on my Page1.aspx that opens up a popup page called
    popup.aspx. I do this with LinkButton.Attr ibutes.Add() on the Page_Load of
    Page1.aspx.
    How can I add server-side code to LinkButton_sear ch_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_sear ch_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
  • Ameet Phadnis(e Tek Global Inc.)

    #2
    RE: popup on Button Click and running server-side button_Click() code?

    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
    RegisterClientS cript functionality to register and run the client script. You
    can google for RegisterClientS cript 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_sear ch on my Page1.aspx that opens up a popup page called
    popup.aspx. I do this with LinkButton.Attr ibutes.Add() on the Page_Load of
    Page1.aspx.
    How can I add server-side code to LinkButton_sear ch_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_sear ch_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

    Comment

    • Milosz Skalecki

      #3
      RE: popup on Button Click and running server-side button_Click() code?

      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.dt d">
      <html xmlns="http://www.w3.org/1999/xhtml" >
      <head runat="server">
      <title>Untitl ed Page</title>
      </head>
      <body>
      <form id="form1" runat="server">
      <div>
      <asp:LinkButt on runat="server" ID="SearchButto n" Text="Search"
      OnClick="Search Button_Click"/>
      </div>
      </form>
      </body>
      </html>

      //code behind

      using System;
      using System.Data;
      using System.Configur ation;
      using System.Collecti ons;
      using System.Web;
      using System.Web.Secu rity;
      using System.Web.UI;
      using System.Web.UI.W ebControls;
      using System.Web.UI.W ebControls.WebP arts;
      using System.Web.UI.H tmlControls;

      public partial class SearchPage : System.Web.UI.P age
      {
      protected void Page_Load(objec t sender, EventArgs e)
      {

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

      Response.Write( date);

      RegisterPopupSc ript();
      }

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

      if (ClientScript.I sStartupScriptR egistered(type, "PopupScrip t"))
      return;

      System.Text.Str ingBuilder script = new System.Text.Str ingBuilder();

      script.Append(" <script language=\"java script\"
      type=\"text/javascript\">\n ");
      script.Append("//<!--\n");
      script.Append(" window.open('po pup.aspx', '_blank',
      'width=400,heig ht=400');");
      script.Append("//-->\n");
      script.Append(" </script>");

      ClientScript.Re gisterStartupSc ript(type, "PopupScrip t", script.ToString ());

      }
      }


      -- END SEARCH PAGE --

      -- BEGIN POPUP PAGE --

      // place label with ID="SearchResul t"


      using System;
      using System.Data;
      using System.Configur ation;
      using System.Collecti ons;
      using System.Web;
      using System.Web.Secu rity;
      using System.Web.UI;
      using System.Web.UI.W ebControls;
      using System.Web.UI.W ebControls.WebP arts;
      using System.Web.UI.H tmlControls;

      public partial class popup : System.Web.UI.P age
      {
      protected void Page_Load(objec t sender, EventArgs e)
      {
      if (!IsPostBack)
      SearchResult.Te xt = Convert.ToStrin g(Session["SearchVariable "]);
      }
      }
      -- END POPUP PAGE --

      --

      Hope this helps

      Milosz Skalecki
      MCP, MCAD


      "VMI" wrote:
      I have a LinkButton_sear ch on my Page1.aspx that opens up a popup page called
      popup.aspx. I do this with LinkButton.Attr ibutes.Add() on the Page_Load of
      Page1.aspx.
      How can I add server-side code to LinkButton_sear ch_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_sear ch_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

      Comment

      Working...