Prob with delegates
-
In my Asp.net application i have divided my web form in to 2 colums.top frame will load a page and it has datagrid control.bottom one have a dropdownlist with few codes. iwant to fill my data grid accourding to the change of my DDL. therefore i create a delegate in my top.aspx form and a function to fill data from DB.and i call above function when change the SelectedIndex of my DDL.now my parameter values passed to top.aspx page but can't fill my DG. it gives error called object reference not set..... how can i fill my DG from another page. note:Also these two pages are in two diff namespace.
-
In my Asp.net application i have divided my web form in to 2 colums.top frame will load a page and it has datagrid control.bottom one have a dropdownlist with few codes. iwant to fill my data grid accourding to the change of my DDL. therefore i create a delegate in my top.aspx form and a function to fill data from DB.and i call above function when change the SelectedIndex of my DDL.now my parameter values passed to top.aspx page but can't fill my DG. it gives error called object reference not set..... how can i fill my DG from another page. note:Also these two pages are in two diff namespace.
Do you have to use frames? You may find it easier when dealing with postbacks to the same page not to use frames. If you do have to use frames, I think you may need to handle this a little differently: in top.aspx, when you get a postback with the new SelectedIndex, you might do a
Response.Redirect()
to a URL that points to the outer frameset page, passing along the new index as a querystring parameter. Use server-side code to pass the querystring parameter from the top page to each FRAME page, and within the FRAME pages, test for the existence of this query-string parameter and respond accordingly (e.g. populate the datagrid). Here are three sample files that show what I mean.file: "framesetWithParams.aspx"
<%@ Page Language="C#" %>
<script runat="server">void Page\_Load(object o, EventArgs e) { // templates for the src attributes of the top & dg frames string frameTop = "framesetWithParams\_top.aspx?index={0}"; string frameDg = "framesetWithParams\_dg.aspx?index={0}"; // retrieve the querystring "index" value string index = Request.QueryString\["index"\]; // set the "src" attributes for each frame accordingly top.Attributes\["src"\] = string.Format(frameTop, index); dg.Attributes\["src"\] = string.Format(frameDg, index); }
</script>
<html>
<head>
<title></title>
<frameset rows="30%,70%">
<frame name='top' id='top' runat='server' />
<frame name='dg' id='dg' runat='server' />
</frameset>
</head>
<body />
</html>file: "framesetWithParams_top.aspx"
(note the use of the<base target=_parent>
tag in the<head>
... this allows the postback from the dropdown selection to refresh the entire page)<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object o, EventArgs e)
{
// look for the index code in the querystring
// (but only the first time; we won't do
// this on a postback)
if (!IsPostBack)
{
string sCode = Request.QueryString["index"];
dd.SelectedValue = sCode;
}
}void HandleSelectedIndexChanged(object o, EventArgs e)
{
// on a postback, redirect to the outer frameset page
// with the selected index
Response.Redirect("framesetWithParams.aspx?index=" -
Do you have to use frames? You may find it easier when dealing with postbacks to the same page not to use frames. If you do have to use frames, I think you may need to handle this a little differently: in top.aspx, when you get a postback with the new SelectedIndex, you might do a
Response.Redirect()
to a URL that points to the outer frameset page, passing along the new index as a querystring parameter. Use server-side code to pass the querystring parameter from the top page to each FRAME page, and within the FRAME pages, test for the existence of this query-string parameter and respond accordingly (e.g. populate the datagrid). Here are three sample files that show what I mean.file: "framesetWithParams.aspx"
<%@ Page Language="C#" %>
<script runat="server">void Page\_Load(object o, EventArgs e) { // templates for the src attributes of the top & dg frames string frameTop = "framesetWithParams\_top.aspx?index={0}"; string frameDg = "framesetWithParams\_dg.aspx?index={0}"; // retrieve the querystring "index" value string index = Request.QueryString\["index"\]; // set the "src" attributes for each frame accordingly top.Attributes\["src"\] = string.Format(frameTop, index); dg.Attributes\["src"\] = string.Format(frameDg, index); }
</script>
<html>
<head>
<title></title>
<frameset rows="30%,70%">
<frame name='top' id='top' runat='server' />
<frame name='dg' id='dg' runat='server' />
</frameset>
</head>
<body />
</html>file: "framesetWithParams_top.aspx"
(note the use of the<base target=_parent>
tag in the<head>
... this allows the postback from the dropdown selection to refresh the entire page)<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object o, EventArgs e)
{
// look for the index code in the querystring
// (but only the first time; we won't do
// this on a postback)
if (!IsPostBack)
{
string sCode = Request.QueryString["index"];
dd.SelectedValue = sCode;
}
}void HandleSelectedIndexChanged(object o, EventArgs e)
{
// on a postback, redirect to the outer frameset page
// with the selected index
Response.Redirect("framesetWithParams.aspx?index="Hello mike, Thank you very much for your answeer.but i have done this by using query string.what i want is to implement common data fill page to all other web ages of my application. you know we can add datagrid individualy by page by page and fill out accourding to parameter fields which we send. In my new web application most of pages has to display entered data from that page.so i want to send these request to one page and fill the DG.also after when user select the griddata,i want to fill out data entry form agin. like :- for the modification.... so this my issue.how can i do this. thankx amal
-
Hello mike, Thank you very much for your answeer.but i have done this by using query string.what i want is to implement common data fill page to all other web ages of my application. you know we can add datagrid individualy by page by page and fill out accourding to parameter fields which we send. In my new web application most of pages has to display entered data from that page.so i want to send these request to one page and fill the DG.also after when user select the griddata,i want to fill out data entry form agin. like :- for the modification.... so this my issue.how can i do this. thankx amal
Build a data tier for your application - it could be as simple as a single class with some static methods for retrieving data from the database, and returning DataTables to the web front-end. Put DataGrid controls on each page necessary, and in each respective Page_Load event, execute the method from your data tier that returns the appropriate DataTable.
-
Build a data tier for your application - it could be as simple as a single class with some static methods for retrieving data from the database, and returning DataTables to the web front-end. Put DataGrid controls on each page necessary, and in each respective Page_Load event, execute the method from your data tier that returns the appropriate DataTable.
Dear Mike, Can you please provide me a sample code to do above task.it will more help full for me to complete my task. Thankx Amal
-
Dear Mike, Can you please provide me a sample code to do above task.it will more help full for me to complete my task. Thankx Amal
class MyDataTier
{
public static DataTable GetSomeData()
{
// .. do whatever is necessary to get a dataset or datatable
// .. e.g. execute a Select command against a database...
// .. or read in an Xml data document...
// .. whatever you need ..
// .. in the end, return the DataSet, or DataTable, or XmlDocument,
// .. or whatever makes sense for your applicationreturn myDataTable;
}
}Then in your ASP.NET web pages you could call the static data tier functions to retrieve the data you need:
void Page_Load(object o, EventArgs e)
{
if (!IsPostBack)
{
this.myDataGrid.DataSource = MyDataTier.GetSomeData();
this.myDataGrid.DataBind();
}
} -
class MyDataTier
{
public static DataTable GetSomeData()
{
// .. do whatever is necessary to get a dataset or datatable
// .. e.g. execute a Select command against a database...
// .. or read in an Xml data document...
// .. whatever you need ..
// .. in the end, return the DataSet, or DataTable, or XmlDocument,
// .. or whatever makes sense for your applicationreturn myDataTable;
}
}Then in your ASP.NET web pages you could call the static data tier functions to retrieve the data you need:
void Page_Load(object o, EventArgs e)
{
if (!IsPostBack)
{
this.myDataGrid.DataSource = MyDataTier.GetSomeData();
this.myDataGrid.DataBind();
}
}Dear Mike, Thanx for the reply.any way what i want is to create common web page to display all the nesessary data request from other pages.not to create a common function and call it on other pages. i just want to create common data view page for other child pages.so when the user select the filling criteria from child page the top.aspx page have to display the correct data. e.g : say user going to modify the project details.but before that he wants to view entered project details.when he click the button which is in bottom.aspx my common data fill page that is top.aspx should fill out all entered project details. at the movement i use querystring for this.but i think it's not practical for this.. as a another solution i can do this by creating user control also.but i just want to do that another way. Thanx