943,097 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1652
  • ASP.NET RSS
Mar 4th, 2010
0

Listbox control in a popup window

Expand Post »
problem:
On the parent page, I have a textfield and an image icon.on clicking the image, a popup (child) should open. The child form has a textbox ,a listbox and a button Go. By default, the listbox should be populated with employee names. When the user types a letter, the appropriate list item should be highlighted . On selecting an item and clicking GO button, the employee id of the selected name should appear in the parent form .

here is the code. I am using Vista, though no errors seem to be cropping, the popup does not occur.



parent.aspx
ASP.NET Syntax (Toggle Plain Text)
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Parent.aspx.cs" Inherits="Parent" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7. <title>Untitled Page</title>
  8. <script type="text/javascript">
  9. function openPopUp()
  10. {
  11. var popUrl = 'Child.aspx';
  12. var name = 'popUp';
  13. var appearence ='dependent=yes,menubar=no,resizable=no,'+
  14. 'status=no,toolbar=no,titlebar=no,' +
  15. 'left=5,top=280,width=230px,height=140px';
  16. var openWindow = window.open(popUrl, name, appearence);
  17. openWindow.focus();
  18. }
  19. </script>
  20. </head>
  21. <body>
  22. <form id="f1" runat="server">
  23. <div>
  24. <asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" style="z-index: 100; left: 284px; position: absolute; top: 33px" />
  25. <asp:TextBox ID="TextBox1" runat="server" Style="z-index: 102; left: 102px; position: absolute;
  26. top: 36px"></asp:TextBox>
  27. </div>
  28. </form>
  29. </body>
  30. </html>
  31.  
  32. Codebehind - parent.aspx
  33. using System;
  34. using System.Data;
  35. using System.Configuration;
  36. using System.Collections;
  37. using System.Web;
  38. using System.Web.Security;
  39. using System.Web.UI;
  40. using System.Web.UI.WebControls;
  41. using System.Web.UI.WebControls.WebParts;
  42. using System.Web.UI.HtmlControls;
  43.  
  44. public partial class Parent : System.Web.UI.Page
  45. {
  46. protected void Page_Load(object sender, EventArgs e)
  47. {
  48.  
  49.  
  50. if (!IsPostBack)
  51. {
  52. this .ImageButton1.Attributes.Add("onclick", "openPopUp('Cd.aspx')");
  53. }
  54.  
  55.  
  56. }
  57. protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  58. {
  59.  
  60. }
  61. }
  62.  
  63.  
  64. child.aspx
  65.  
  66. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Child.aspx.cs" Inherits="Child" %>
  67.  
  68. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  69.  
  70. <html xmlns="http://www.w3.org/1999/xhtml" >
  71. <head runat="server">
  72. <title>Untitled Page</title>
  73. <script language="javascript">
  74. function GetRowValue()
  75. {
  76.  
  77. window.opener.f1.TextBox1.value=document.form1.lst Item.value;
  78. window.close ();
  79. }
  80. </script>
  81. </head>
  82. <body>
  83. <form id="form1" runat="server">
  84. <div>
  85. <asp:TextBox ID="txtList" runat="server"></asp:TextBox>
  86. <asp:Button ID="btngo" runat="server" OnClick="btngo_Click" Text="Go" /><br />
  87. <br />
  88. <asp:ListBox ID="lstItem" runat="server" AutoPostBack="True" OnSelectedIndexChanged="lstItem_SelectedIndexChanged"></asp:ListBox>&nbsp;
  89. <br />
  90. </div>
  91. </form>
  92. </body>
  93. </html>
  94.  
  95.  
  96. codebehind - child.aspx
  97. using System;
  98. using System.Data;
  99. using System.Configuration;
  100. using System.Collections;
  101. using System.Web;
  102. using System.Web.Security;
  103. using System.Web.UI;
  104. using System.Web.UI.WebControls;
  105. using System.Web.UI.WebControls.WebParts;
  106. using System.Web.UI.HtmlControls;
  107. using System.Data.SqlClient;
  108. using Sample;
  109.  
  110. public partial class Child : System.Web.UI.Page
  111. {
  112. protected void Page_Load(object sender, EventArgs e)
  113. {
  114.  
  115. if (!IsPostBack)
  116. {
  117. Logic obj = new Logic();
  118. string str = "select zone_name from zone_details";
  119. DataSet ds = obj.getDataSet(str);
  120. lstItem.DataSource = ds;
  121. lstItem.DataTextField = "zone_name";
  122. lstItem.DataBind();
  123. }
  124.  
  125. this.lstItem.Attributes.Add("onclick", "GetRowValue()");
  126.  
  127.  
  128. }
  129. protected void btngo_Click(object sender, EventArgs e)
  130. {
  131. //Logic obj = new Logic();
  132. //string str = "select zone_name from zone_details where zone_name='"+txtList .Text +"'";
  133. //DataSet ds = obj.getDataSet(str);
  134.  
  135. }
  136. protected void lstItem_SelectedIndexChanged(object sender, EventArgs e)
  137. {
  138.  
  139. }
  140.  
  141. }
  142.  
  143.  
  144. I have created a namespace 'Sample' used in the above code.
  145.  
  146. using System;
  147. using System.Data;
  148. using System.Configuration;
  149. using System.Web;
  150. using System.Web.Security;
  151. using System.Web.UI;
  152. using System.Web.UI.WebControls;
  153. using System.Web.UI.WebControls.WebParts;
  154. using System.Web.UI.HtmlControls;
  155. using System.Data.SqlClient;
  156.  
  157. namespace Sample
  158. {
  159. public class Logic
  160. {
  161. public DataSet getDataSet(string strsql)
  162. {
  163. string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
  164. SqlConnection con = new SqlConnection(constr);
  165. SqlCommand cmd = new SqlCommand(strsql , con);
  166. try
  167. {
  168. con.Open();
  169. SqlDataAdapter ad = new SqlDataAdapter(cmd);
  170. DataSet ds = new DataSet();
  171. ad.Fill(ds);
  172. return ds;
  173. }
  174. catch (Exception ex)
  175. {
  176. throw ex;
  177. }
  178. finally
  179. {
  180. con.Close();
  181. cmd.Dispose();
  182. con.Dispose();
  183. }
  184. }
  185. }
  186. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
s_sankari is offline Offline
1 posts
since Mar 2010
Mar 5th, 2010
0
Re: Listbox control in a popup window
Try out this,
ASP.NET Syntax (Toggle Plain Text)
  1. ...
  2. function GetRowValue() {
  3. window.opener.document.getElementById("TextBox1").value = document.getElementById("lstItem").value;
  4. window.close();
  5. }
  6. ...
Moderator
Reputation Points: 2134
Solved Threads: 1227
Posting Genius
adatapost is offline Offline
6,524 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: update in datalist
Next Thread in ASP.NET Forum Timeline: I want a miniproject based on asp.net





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


Follow us on Twitter


© 2011 DaniWeb® LLC