473,320 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

econVictim
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:LinkButton Text="userIdlink" OnCommand="linkbutton1" CommandArgument="12" runat="server" />
<asp:Label Text="" ID="lblTest" runat="server"></asp:Label>
</div>
</form>
[/HTML]

this is the codebehind
Expand|Select|Wrap|Line Numbers
  1. namespace popup 
  2. {
  3.     public partial class _Default : System.Web.UI.Page
  4.     {
  5.         protected void Page_Load(object sender, EventArgs e)
  6.         {
  7.  
  8.         }
  9.  
  10.         public void linkbutton1(object sender, EventArgs e)
  11.         {
  12.             string passValue = "";
  13.             passValue = ((LinkButton)sender).CommandArgument;
  14.  
  15.             HtmlGenericControl div = new HtmlGenericControl("div");
  16.             //div.InnerText = "Do you want to request BLAH as your friend?";
  17.             div.Attributes.Add("id","popup");
  18.             div.Attributes.Add("style", "zIndex:3; width:350px; height:150px; border: 2px solid silver; position: absolute; top: 150px; left: 150px; background:#eaeaea; padding: 15px;");
  19.  
  20.             Button btnRequest = new Button();
  21.             btnRequest.ID = "btnRequest";
  22.             btnRequest.Text = "Send my request.";
  23.             btnRequest.Click += new EventHandler(sendRequest);
  24.             btnRequest.Attributes.Add("runat", "server");
  25.  
  26.             Button btnCancel = new Button();
  27.             btnCancel.ID = "btnCancel";
  28.             btnCancel.Text = "Cancel my request.";
  29.             btnCancel.Click += new EventHandler(cancelRequest);
  30.  
  31.             Label lblMessage = new Label();
  32.             lblMessage.ID = "lblMessage";
  33.             lblMessage.Text = "Is " + passValue + " the correct userId?<br>";
  34.  
  35.             div.Controls.Add(lblMessage);
  36.             div.Controls.Add(btnRequest);
  37.             div.Controls.Add(btnCancel);
  38.  
  39.             this.form1.Controls.Add(div);
  40.         }
  41.  
  42.         public void sendRequest(object sender, System.EventArgs e)
  43.         {
  44.             Response.Write("this function does nothing.");
  45.         }
  46.         public void cancelRequest(object sender, System.EventArgs e)
  47.         {
  48.             Response.Write("this function does nothing.");
  49.         }
  50.     }
  51. }
Oct 23 '08 #1
5 2267
nateraaaa
663 Expert 512MB
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
Oct 23 '08 #2
Frinavale
9,735 Expert Mod 8TB
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.Visible = false). When your link button is clicked change the style of the to display:block (or thePanel.Visible=true).

-Frinny
Oct 23 '08 #3
here is a link to the page where the code example can be seen
www.boilerconnections.com/aaronstests/search/popup.aspx

thank you for replying, i'm going to modify the code tonight
Oct 23 '08 #4
ok i've fixed the errors... thanks guys.. this is what i've ended up doing

.aspx :

Expand|Select|Wrap|Line Numbers
  1.     <form id="form1" runat="server">
  2.  
  3.         <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" CommandArgument="12">LinkButton</asp:LinkButton>&nbsp;
  4.         <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;">
  5.             <asp:Label Text="" ID="lblTest" runat="server"></asp:Label>
  6.             <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send Request" />
  7.             <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Cancel Request" /></div></asp:Panel>
  8.     </form>
  9.  
and the aspx.cs:

Expand|Select|Wrap|Line Numbers
  1. public partial class _Default : System.Web.UI.Page 
  2. {
  3.     protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.         Panel1.Visible = false;
  6.     }
  7.     protected void Button1_Click(object sender, EventArgs e)
  8.     {
  9.         Response.Write("send request");
  10.     }
  11.     protected void Button2_Click(object sender, EventArgs e)
  12.     {
  13.         Response.Write("cancel request");
  14.     }
  15.     protected void LinkButton1_Click(object sender, EventArgs e)
  16.     {
  17.         string passValue = "";
  18.         passValue = ((LinkButton)sender).CommandArgument;
  19.         lblTest.Text = "Is" + passValue + " the correct userId?<br>";
  20.         Panel1.Visible = true;
  21.     }
  22. }
  23.  
after 10 minutes working with visual studio and the help you've mentioned, i've been able to realize many of my misunderstandings about writing code. i've been writing all of my code from scratch in dreamweaver.

the working code example is on
http://www.boilerconnections.com/aaronstests/search/popup2.aspx
Oct 23 '08 #5
Frinavale
9,735 Expert Mod 8TB
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
Oct 24 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

38
by: Shaun McKinnon | last post by:
HI...Here's my problem...I have a popup window that loads when i want it to, but it's not sized properly. I've set the size, but it doesn't seem to work. I've been on 8 different websites to find...
2
by: Mark | last post by:
The situtation is that I'm trying to ensure that certain functions are only called by functions that I want them to be called from. I have a popup window which has a function which calls a function...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
26
by: Raffi | last post by:
Hi, We have a database application that runs in a popup Internet Explorer application window. The reason for this is to isolate the casual user from the address bar and the typical IE navigation...
4
by: Davey | last post by:
I have a website which has a popup window (this only opens when the user chooses to open it). In the popup window I have a <select> control which lists a selection of "classes". Each class has a...
13
by: ldan | last post by:
Hi everybody, I would not consider myself an expert in javascript - but so far whatever I know, helped me reaching my goals. Recently I started to experience a lot of javascript errors related...
3
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
5
by: midnight_use_only | last post by:
hi all, quick question, how do you submit a form to a parent window from a child popup window? i have the following and all online documentation *suggests* that it should work but it does NOT: ...
4
by: Macbane | last post by:
Hi, I have a 'main' form called frmIssues which has a subform control (named linkIssuesDrug) containing the subform sfrmLink_Issues_Drugs. A control button on the main form opens a pop-up form...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.