a popup form that doesn't execute functions- web c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • econVictim
    New Member
    • Oct 2008
    • 13

    a popup form that doesn't execute functions- web c#

    hey guys, i'm new to working with .net c#. I've been doing some more advanced things without knowing much about what i'm doing... I need to create this popup window without using the javascript.. i've been mostly successfull using some simple code however my buttons on the popup don't execute. any ideas and solutions would be greatly appreciated... thank you

    this is the front form... form1

    [HTML]
    <form id="form1" runat="server">
    <div>
    <asp:LinkButt on Text="userIdlin k" OnCommand="link button1" CommandArgument ="12" runat="server" />
    <asp:Label Text="" ID="lblTest" runat="server"> </asp:Label>
    </div>
    </form>
    [/HTML]

    this is the codebehind
    Code:
    namespace popup 
    {
    	public partial class _Default : System.Web.UI.Page
    	{
    		protected void Page_Load(object sender, EventArgs e)
    		{
    	
    		}
    	
    		public void linkbutton1(object sender, EventArgs e)
    		{
    			string passValue = "";
    			passValue = ((LinkButton)sender).CommandArgument;
    		
    			HtmlGenericControl div = new HtmlGenericControl("div");
    			//div.InnerText = "Do you want to request BLAH as your friend?";
    			div.Attributes.Add("id","popup");
    			div.Attributes.Add("style", "zIndex:3; width:350px; height:150px; border: 2px solid silver; position: absolute; top: 150px; left: 150px; background:#eaeaea; padding: 15px;");
    			
    			Button btnRequest = new Button();
    			btnRequest.ID = "btnRequest";
    			btnRequest.Text = "Send my request.";
    			btnRequest.Click += new EventHandler(sendRequest);
    			btnRequest.Attributes.Add("runat", "server");
    			
    			Button btnCancel = new Button();
    			btnCancel.ID = "btnCancel";
    			btnCancel.Text = "Cancel my request.";
    			btnCancel.Click += new EventHandler(cancelRequest);
    			
    			Label lblMessage = new Label();
    			lblMessage.ID = "lblMessage";
    			lblMessage.Text = "Is " + passValue + " the correct userId?<br>";
    			
    			div.Controls.Add(lblMessage);
    			div.Controls.Add(btnRequest);
    			div.Controls.Add(btnCancel);
    
    			this.form1.Controls.Add(div);
    		}
    		
    		public void sendRequest(object sender, System.EventArgs e)
    		{
    			Response.Write("this function does nothing.");
    		}
    		public void cancelRequest(object sender, System.EventArgs e)
    		{
    			Response.Write("this function does nothing.");
    		}
    	}
    }
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    So when you click the linkButton you want to open a new .aspx page? On the new .aspx page you need to wire up the onClick event for any buttons on the page. You can do this by viewing the .aspx page in the IDE (in design mode) and double clicking on a button to generate the _Click event of the button.

    Nathan

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      You shouldn't use Response.Write. This will place the content "Somewhere" on the page...this could be before the <body> or <html> tag and so your page will no longer be valid.

      Aside from that, your controls within your "popup" will not work because you are declaring them with a scope of the method that creates them. They have to be declared outside of the method that handles linkbutton1 button click and have to be added to the <div> before the page is loaded.


      See this article on how to use dynamic controls in ASP.NET for more information.

      What I would recommend is not even dynamically creating your labels and buttons. Simple put a panel on your page that will server as your PopUp (this will be rendered as a <div>) and set it's style to be display:none (or even easier set thePanel.Visibl e = false). When your link button is clicked change the style of the to display:block (or thePanel.Visibl e=true).

      -Frinny

      Comment

      • econVictim
        New Member
        • Oct 2008
        • 13

        #4
        here is a link to the page where the code example can be seen
        www.boilerconne ctions.com/aaronstests/search/popup.aspx

        thank you for replying, i'm going to modify the code tonight

        Comment

        • econVictim
          New Member
          • Oct 2008
          • 13

          #5
          ok i've fixed the errors... thanks guys.. this is what i've ended up doing

          .aspx :

          Code:
              <form id="form1" runat="server">
          
                  <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" CommandArgument="12">LinkButton</asp:LinkButton>&nbsp;
                  <asp:Panel ID="Panel1" runat="server" Height="112px" Width="242px"><div style="z-Index:3; width:350px; height:150px; border: 2px solid silver; position: absolute; top: 150px; left: 150px; background:#eaeaea; padding: 15px;">
          			<asp:Label Text="" ID="lblTest" runat="server"></asp:Label>
                      <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send Request" />
                      <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Cancel Request" /></div></asp:Panel>
              </form>
          and the aspx.cs:

          Code:
          public partial class _Default : System.Web.UI.Page 
          {
              protected void Page_Load(object sender, EventArgs e)
              {
                  Panel1.Visible = false;
              }
              protected void Button1_Click(object sender, EventArgs e)
              {
                  Response.Write("send request");
              }
              protected void Button2_Click(object sender, EventArgs e)
              {
                  Response.Write("cancel request");
              }
              protected void LinkButton1_Click(object sender, EventArgs e)
              {
          		string passValue = "";
          		passValue = ((LinkButton)sender).CommandArgument;
                  lblTest.Text = "Is" + passValue + " the correct userId?<br>";
          		Panel1.Visible = true;
              }
          }
          after 10 minutes working with visual studio and the help you've mentioned, i've been able to realize many of my misunderstandin gs about writing code. i've been writing all of my code from scratch in dreamweaver.

          the working code example is on
          http://www.boilerconne ctions.com/aaronstests/search/popup2.aspx

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by econVictim
            o
            ...I've been writing all of my code from scratch in dreamweaver.
            Oh yuck.

            I'm glad we were able to help you to get it to work :)

            -Frinny

            Comment

            Working...