N
news
Not really sure if this is a javascript problem or C# - sorry if in
wrong place.
Modal Forms Question in Web Application
I have two web forms: Form1 and Form2
Form1 calls Form2 using showModalDialog
var WinSettings = "resizable:no;dialogHeight:600px;dialogWidth:600"
var result = window.showModalDialog("Form2.aspx",null, WinSettings);
Form2 has a ListBox, a Label and a Button. The listbox is populated
from a sql call to the database. The "SelectedIndexChanged" event
changes the text appearing on the label to the value associated from
the ListBox. The Button closes the form and returns the text from the
label. Form2 works properly when ran by itself.
However, when I load it using showModalDialog from Form1, the first
time the "SelectedIndexChanged" event fires, a new window opens up of
class Form2 rather than just changing the text in the Label field.
Any help would be appreciated.
-------------Form2 Code Behind-----------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EnterpriseObjects;
using StoreObjects;
using System.Data.SqlClient;
using System.Configuration;
namespace ASPNET.StarterKit.Portal
{
public class Form2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblArticleView;
protected DataView dvp;
protected System.Web.UI.WebControls.ListBox ListBox1;
protected DataSet asas;
private void Page_Load(object sender, System.EventArgs e)
{
EnterpriseApplication.Application.ConnectionString =
ConfigurationSettings.AppSettings["ConnectionString"].ToString();
System.Data.SqlClient.SqlConnection connection = new
System.Data.SqlClient.SqlConnection(EnterpriseApplication.Application.Connec
tionString);
asas = new DataSet();
SqlDataAdapter ad;
ad = new SqlDataAdapter("Select * from Store_Articles", connection);
ad.Fill(asas, "Table");
dvp = new DataView(asas.Tables["Table"]);
if(!(Page.IsPostBack))
{
dvp.Sort = "SortOrder";
ListBox1.DataSource = dvp;
ListBox1.DataMember = "Table";
ListBox1.DataValueField = "ArticleID";
ListBox1.DataTextField = "Name";
ListBox1.DataBind();
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.ListBox1.SelectedIndexChanged += new
System.EventHandler(this.ListBox1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
private void ListBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
dvp.RowFilter = "ArticleID = '" + ListBox1.SelectedValue.ToString() +
"'";
lblArticleView.Text = dvp[0].Row["Text"].ToString();
}
}
}
wrong place.
Modal Forms Question in Web Application
I have two web forms: Form1 and Form2
Form1 calls Form2 using showModalDialog
var WinSettings = "resizable:no;dialogHeight:600px;dialogWidth:600"
var result = window.showModalDialog("Form2.aspx",null, WinSettings);
Form2 has a ListBox, a Label and a Button. The listbox is populated
from a sql call to the database. The "SelectedIndexChanged" event
changes the text appearing on the label to the value associated from
the ListBox. The Button closes the form and returns the text from the
label. Form2 works properly when ran by itself.
However, when I load it using showModalDialog from Form1, the first
time the "SelectedIndexChanged" event fires, a new window opens up of
class Form2 rather than just changing the text in the Label field.
Any help would be appreciated.
-------------Form2 Code Behind-----------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EnterpriseObjects;
using StoreObjects;
using System.Data.SqlClient;
using System.Configuration;
namespace ASPNET.StarterKit.Portal
{
public class Form2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblArticleView;
protected DataView dvp;
protected System.Web.UI.WebControls.ListBox ListBox1;
protected DataSet asas;
private void Page_Load(object sender, System.EventArgs e)
{
EnterpriseApplication.Application.ConnectionString =
ConfigurationSettings.AppSettings["ConnectionString"].ToString();
System.Data.SqlClient.SqlConnection connection = new
System.Data.SqlClient.SqlConnection(EnterpriseApplication.Application.Connec
tionString);
asas = new DataSet();
SqlDataAdapter ad;
ad = new SqlDataAdapter("Select * from Store_Articles", connection);
ad.Fill(asas, "Table");
dvp = new DataView(asas.Tables["Table"]);
if(!(Page.IsPostBack))
{
dvp.Sort = "SortOrder";
ListBox1.DataSource = dvp;
ListBox1.DataMember = "Table";
ListBox1.DataValueField = "ArticleID";
ListBox1.DataTextField = "Name";
ListBox1.DataBind();
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.ListBox1.SelectedIndexChanged += new
System.EventHandler(this.ListBox1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
private void ListBox1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
dvp.RowFilter = "ArticleID = '" + ListBox1.SelectedValue.ToString() +
"'";
lblArticleView.Text = dvp[0].Row["Text"].ToString();
}
}
}