943,973 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 81470
  • ASP.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 16th, 2007
0

Popup window on button click

Expand 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Feb 16th, 2007
0

Re: Popup window on button click

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…

html Syntax (Toggle Plain Text)
  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.)
c# Syntax (Toggle Plain Text)
  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.
Reputation Points: 12
Solved Threads: 2
Junior Poster
M_K_Higa is offline Offline
102 posts
since Sep 2006
Feb 22nd, 2007
0

Re: Popup window on button click

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
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Feb 22nd, 2007
0

Re: Popup window on button click

g
Reputation Points: 10
Solved Threads: 0
Newbie Poster
narkhedeuday is offline Offline
1 posts
since Feb 2007
Feb 22nd, 2007
0

Re: Popup window on button click

I think session concept works for ur problem
Reputation Points: 10
Solved Threads: 1
Light Poster
aravindkishore is offline Offline
29 posts
since Feb 2007
Feb 22nd, 2007
0

Re: Popup window on button click

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
html Syntax (Toggle Plain Text)
  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
html Syntax (Toggle Plain Text)
  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>
Reputation Points: 12
Solved Threads: 2
Junior Poster
M_K_Higa is offline Offline
102 posts
since Sep 2006
Feb 22nd, 2007
0

Re: Popup window on button click

Thanks. just gonna try
Reputation Points: 10
Solved Threads: 0
Light Poster
Sarah Lee is offline Offline
45 posts
since Sep 2006
Mar 1st, 2007
0

Re: Popup window on button click

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>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bazpaul is offline Offline
1 posts
since Mar 2007
Mar 1st, 2007
0

Re: Popup window on button click

Looks like a typo -- you have dialogHeiht: 150x;

it should be dialogHeiht: 150px;
Reputation Points: 12
Solved Threads: 2
Junior Poster
M_K_Higa is offline Offline
102 posts
since Sep 2006
Nov 13th, 2008
0

Popup window on button click

Click to Expand / Collapse  Quote originally posted by Sarah Lee ...
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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
rajbav2000 is offline Offline
4 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: xml to dataset
Next Thread in ASP.NET Forum Timeline: FolderBrowserDialog in ASP.NET





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC