| | |
Popup window on button click
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 45
Reputation:
Solved Threads: 0
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
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
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…
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.)
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.
Here’s an expmple…
html Syntax (Toggle Plain Text)
<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.)
c# Syntax (Toggle Plain Text)
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.
-Mike
•
•
Join Date: Sep 2006
Posts: 45
Reputation:
Solved Threads: 0
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
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
Ok. Instead of using
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
child.aspx
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)
<!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
html Syntax (Toggle Plain Text)
<!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><br /> <input id="Text1" type="text" value="Enter a value..." /><br /> <input id="Button1" type="button" value="Return a value..." onclick="DoOnclick(Text1);" /> </div> </form> </body> </html>
-Mike
•
•
Join Date: Mar 2007
Posts: 1
Reputation:
Solved Threads: 0
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¶m1=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>
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¶m1=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>
•
•
Join Date: Oct 2008
Posts: 4
Reputation:
Solved Threads: 1
•
•
•
•
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
try this out u will get the pop window only but u wil not get a text box
![]() |
Similar Threads
- Make An Asp Popup Window--help Me About This... (JavaScript / DHTML / AJAX)
Other Threads in the ASP.NET Forum
- Previous Thread: xml to dataset
- Next Thread: FolderBrowserDialog in ASP.NET
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv gridview gudi iis javascript list listbox login menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





