954,198 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Popup window on button click

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

Sarah Lee
Light Poster
45 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

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…

<form id="form1" runat="server">
<div>
  <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="HiddenField1.value = prompt('Enter your feedback','');" />
  <asp:HiddenField ID="HiddenField1" runat="server" />
  <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</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.)

protected void Page_Load(object sender, EventArgs e) {
  if(IsPostBack) {
    Label1.Text = HiddenField1.Value;
  }
}


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.

M_K_Higa
Junior Poster
102 posts since Sep 2006
Reputation Points: 12
Solved Threads: 2
 

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

popup.aspx

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

Sarah Lee
Light Poster
45 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 
narkhedeuday
Newbie Poster
1 post since Feb 2007
Reputation Points: 10
Solved Threads: 0
 

I think session concept works for ur problem

aravindkishore
Light Poster
29 posts since Feb 2007
Reputation Points: 10
Solved Threads: 1
 

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Parent Page</title>
<script type="text/javascript">
  function DoOnclick() {
    var RetVal="Test: The child.html page will change this value...";
    alert(RetVal); 
    RetVal = window.showModalDialog("child.html","","dialogHeight: 150px; dialogWidth: 300px;");
    alert(RetVal); 
  }
</script>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <input id="Button1" type="button" value="Open Child..." onclick="DoOnclick();" />
    </div>
  </form>
</body>
</html>


child.aspx

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Child Page</title>
<script type="text/javascript">
  function DoOnclick(arg) {
    if(arg.value == "Enter a value...") {
      alert("Do some kind of validation...");
      return false; // Make sure the user changes the value
    } else {
      window.returnValue = arg.value;
    }
    window.close();
  }
</script>
</head>
<body>
  <form id="form1" runat="server">
    <div>
      <strong>This is the modal box...</strong>
      <input id="Text1" type="text" value="Enter a value..." />
      <input id="Button1" type="button" value="Return a value..." onclick="DoOnclick(Text1);" />
    </div>
  </form>
</body>
</html>
M_K_Higa
Junior Poster
102 posts since Sep 2006
Reputation Points: 12
Solved Threads: 2
 

Thanks. just gonna try

Sarah Lee
Light Poster
45 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 
bazpaul
Newbie Poster
1 post since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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

it should be dialogHeiht: 150px; :)

M_K_Higa
Junior Poster
102 posts since Sep 2006
Reputation Points: 12
Solved Threads: 2
 

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("");
try this out u will get the pop window only but u wil not get a text box

rajbav2000
Newbie Poster
4 posts since Oct 2008
Reputation Points: 10
Solved Threads: 1
 

I'm not sure I understand. Is there a question here?

M_K_Higa
Junior Poster
102 posts since Sep 2006
Reputation Points: 12
Solved Threads: 2
 

You need to update your code as follows:

void Page_load(object sender, EventArgs e)
{
Button1.Attributes.Add( "onclick", "popWin();return false;" );
}

Without that additional Javascript statement, the button would still cause a postback.

sandypeter111
Newbie Poster
8 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="HiddenField1.value = prompt('Enter your feedback','');" />
  <asp:HiddenField ID="HiddenField1" runat="server" />


This looks precisely what I require. However with the "HiddenField1.value = " bit I don't get any prompt. It works if I remove it.

Any ideas? (I'm using VB, BTW. But, at the moment it's jsut getting the box to open that's the problem.)

anthonyqkiernan
Newbie Poster
1 post since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You