Nick_011
asked on
Cannot call C# function on closing Asp.net web page
Hi
I get the following error "Microsoft JScript runtime error: 'null' is null or not an object"
at this line btn.click(btnHidden_Click) when running the code below ;
I just need some way of calling a server C# function to dispose a few variables
when a user closes the form. I think the issue is with the master form however
all variations of document.getElementById('b tnHidden') ; thatI've tried doesnt seam
to work
Any assistance would be appreciated
Kind regards
Nick
Asp.net 2008 Aspx
<%@ Page Theme="MainTheme" Language="C#" MasterPageFile="~/Yyyyyy.M aster" . . . . .
. . . . . . . . . . . .. . . .. . . ..
<asp:Content ID="Content1" ContentPlaceHolderID="cphT itle" runat="server" >
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphB ody" runat="server" >
<script type="text/javascript">
window.onunload = ReleaseVariables()
function ReleaseVariables ()
{
var btn = document.getElementById('b tnHidden') ;
btn.click(btnHidden_Click) ;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
. . . . . . . .
</table>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<input type="button" id="btnHidden" value="button" onclick=btnHidden_Click/>
</asp:Content>
c# code behind
protected void btnHidden_Click(object sender, EventArgs e)
{
if (dv != null) dv.Dispose();
if (dv2 != null) dv2.Dispose();
}
I get the following error "Microsoft JScript runtime error: 'null' is null or not an object"
at this line btn.click(btnHidden_Click)
I just need some way of calling a server C# function to dispose a few variables
when a user closes the form. I think the issue is with the master form however
all variations of document.getElementById('b
to work
Any assistance would be appreciated
Kind regards
Nick
Asp.net 2008 Aspx
<%@ Page Theme="MainTheme" Language="C#" MasterPageFile="~/Yyyyyy.M
. . . . . . . . . . . .. . . .. . . ..
<asp:Content ID="Content1" ContentPlaceHolderID="cphT
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphB
<script type="text/javascript">
window.onunload = ReleaseVariables()
function ReleaseVariables ()
{
var btn = document.getElementById('b
btn.click(btnHidden_Click)
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
. . . . . . . .
</table>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<input type="button" id="btnHidden" value="button" onclick=btnHidden_Click/>
</asp:Content>
c# code behind
protected void btnHidden_Click(object sender, EventArgs e)
{
if (dv != null) dv.Dispose();
if (dv2 != null) dv2.Dispose();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're not storing a copy of the object in the session, but only a reference to it. As soon as you call Dispose on the DataView, it is also disposed inside the Session collection.
ASKER
Thanks that does explain the situation.
ASKER
After looking at my source code again, I cant understand why the session variables arn't
preserving the dataview variables. It used to work before the dataview variables were
disposed
OraAdapter = new OracleDataAdapter(OraComma
OraDataset = new DataSet();
OraDataset.Clear();
OraAdapter.Fill(OraDataset
// set some gridview properties
GridView1.AllowPaging = true;
GridView1.PageSize = 14;
// bind dataset to grid
GridView1.DataSourceID = null;
dv = OraDataset.Tables[0].AsDat
Session["dataView"] = dv;
GridView1.DataSource = dv;
GridView1.DataBind();
protected void GridView1_PageIndexChangin
GridViewPageEventArgs e)
{
// get dataview from session
dv = (DataView)Session["dataVie
GridView1.DataSource = dv;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind(); // re-bind data
/*if (dv != null)
{
dv.Dispose();
dv = null;
}*/
}
public void bindGridView(string sortExp, string sortDir)
{
dv = (DataView)Session["dataVie
GridView1.DataSource = dv;
if (sortExp != string.Empty)
{
dv.Sort = string.Format("{0} {1}", sortExp, sortDir);
}
GridView1.DataSource = dv;
GridView1.DataBind();
/*if (dv != null)
{
dv.Dispose();
dv = null;
}*/
}