Popup window on button click

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Popup window on button click

 
0
  #1
Feb 16th, 2007
Hi

In my application, i would like to use the popup window concept.
When the user clciks a button, a popup window should appear, with a textbox to enter a value.
on closing the popup window, the user entered value should get saved into a table


I am using asp.net 2.0

Can anyone please tel, what all are the things to be noted for this?

thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 100
Reputation: M_K_Higa is an unknown quantity at this point 
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster

Re: Popup window on button click

 
0
  #2
Feb 16th, 2007
Since you are capturing user action via popup, you will most likely use client side scripting to get the user input. Once you get the user input, you can set it to some control in your form which will get sent to your server when the form is submitted.

Here’s an expmple…

  1. <form id="form1" runat="server">
  2. <div>
  3. <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="HiddenField1.value = prompt('Enter your feedback','');" />
  4. <asp:HiddenField ID="HiddenField1" runat="server" />
  5. <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  6. </div>
  7. </form>

This code handles the user input on the server side. (In this case, it simply displays it in a label, but at this point you get to decide what to do with it.)
  1. protected void Page_Load(object sender, EventArgs e) {
  2. if(IsPostBack) {
  3. Label1.Text = HiddenField1.Value;
  4. }
  5. }

The button has a client script calling the prompt function. The value returned by the prompt function is set to the value of the hidden field, which gets submitted to the server. NOTE: In production code, you have to validate the user input.
-Mike
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Re: Popup window on button click

 
0
  #3
Feb 22nd, 2007
Thanks for the reply.
Actually i am trying in following way , but struck with this

Suppose if i want to do like this.

parent.aspx
<asp:button id="button1" onclick="openwindow()" ruant="server/>
<script>
function openwindow()
{
window.open("popup.aspx", "mywindow",""...)
}
</script>

popup.aspx
<asp:textbox...>
<asp:button onclcik="adduser"...>
<asp:button onclick="close"..>

The user enters value in textbox of popup.aspx
How can i catch that value in parent.aspx method,( i want to get the value through server side) where i set
dim name as string=" " ----------------> text entered in popup window textbox

Thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 1
Reputation: narkhedeuday is an unknown quantity at this point 
Solved Threads: 0
narkhedeuday narkhedeuday is offline Offline
Newbie Poster

Re: Popup window on button click

 
0
  #4
Feb 22nd, 2007
g
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 29
Reputation: aravindkishore is an unknown quantity at this point 
Solved Threads: 1
aravindkishore aravindkishore is offline Offline
Light Poster

Re: Popup window on button click

 
0
  #5
Feb 22nd, 2007
I think session concept works for ur problem
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 100
Reputation: M_K_Higa is an unknown quantity at this point 
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster

Re: Popup window on button click

 
0
  #6
Feb 22nd, 2007
Ok. Instead of using window.open, you can use the window.showModalDialog method.

The info gathering is still done on the client side, so there's not much asp.net stuff going on here. Just set the returned value to a field that can be returned to the server and you should be able to do your asp.net stuff as usual.

On a related note, you may run into problems with popup blockers so make sure you test very well.

Anyway, here some sample code...

parent.aspx
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Parent Page</title>
  5. <script type="text/javascript">
  6. function DoOnclick() {
  7. var RetVal="Test: The child.html page will change this value...";
  8. alert(RetVal);
  9. RetVal = window.showModalDialog("child.html","","dialogHeight: 150px; dialogWidth: 300px;");
  10. alert(RetVal);
  11. }
  12. </script>
  13. </head>
  14. <body>
  15. <form id="form1" runat="server">
  16. <div>
  17. <input id="Button1" type="button" value="Open Child..." onclick="DoOnclick();" />
  18. </div>
  19. </form>
  20. </body>
  21. </html>

child.aspx
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4. <title>Child Page</title>
  5. <script type="text/javascript">
  6. function DoOnclick(arg) {
  7. if(arg.value == "Enter a value...") {
  8. alert("Do some kind of validation...");
  9. return false; // Make sure the user changes the value
  10. } else {
  11. window.returnValue = arg.value;
  12. }
  13. window.close();
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <form id="form1" runat="server">
  19. <div>
  20. <strong>This is the modal box...</strong><br />
  21. <input id="Text1" type="text" value="Enter a value..." /><br />
  22. <input id="Button1" type="button" value="Return a value..." onclick="DoOnclick(Text1);" />
  23. </div>
  24. </form>
  25. </body>
  26. </html>
-Mike
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 45
Reputation: Sarah Lee is an unknown quantity at this point 
Solved Threads: 0
Sarah Lee Sarah Lee is offline Offline
Light Poster

Re: Popup window on button click

 
0
  #7
Feb 22nd, 2007
Thanks. just gonna try
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1
Reputation: bazpaul is an unknown quantity at this point 
Solved Threads: 0
bazpaul bazpaul is offline Offline
Newbie Poster

Re: Popup window on button click

 
0
  #8
Mar 1st, 2007
Hi

This is a nice example and as a beginner has helped my nicely with a project im working on. However im am having a little problem. When i change the dialog box height and width it has no effect on the size of the box!!!

Can anyone suggest what could be going wrong, heres some of my code;

<code>
<
scripttype="text/javascript">
function DoOnclick()
{
var RetVal="";
RetVal = window.showModalDialog("email_prompt.aspx?name=SS_Server_Detail_Report&param1=1026","","dialogHeight: 150x; dialogWidth: 400px; dialogTop: 250px; dialogLeft: 500px; edge: Sunken; resizable: Yes; status: No;");
alert(RetVal);
}
</script>
</
head>
<
body>
<formid="form1"runat="server">
<div>
<inputid="Button1"type="button"value="Print Report"onclick="DoOnclick();"/>

<!-- DoOnclick(); -->

</form>
</
body>
</
html>
</code>
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 100
Reputation: M_K_Higa is an unknown quantity at this point 
Solved Threads: 2
M_K_Higa's Avatar
M_K_Higa M_K_Higa is offline Offline
Junior Poster

Re: Popup window on button click

 
0
  #9
Mar 1st, 2007
Looks like a typo -- you have dialogHeiht: 150x;

it should be dialogHeiht: 150px;
-Mike
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 4
Reputation: rajbav2000 is an unknown quantity at this point 
Solved Threads: 1
rajbav2000 rajbav2000 is offline Offline
Newbie Poster

Popup window on button click

 
0
  #10
Nov 13th, 2008
Originally Posted by Sarah Lee View Post
Hi

In my application, i would like to use the popup window concept.
When the user clciks a button, a popup window should appear, with a textbox to enter a value.
on closing the popup window, the user entered value should get saved into a table


I am using asp.net 2.0

Can anyone please tel, what all are the things to be noted for this?

thanks
hi this is rajamani and the coding for pop up window is Response.Write("<script>window.alert('Welcome')</script>");
try this out u will get the pop window only but u wil not get a text box
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC