Reputation: 299
I am developing an application which consists of 2 forms, parent and child.
In parent form I have a frame. If button 1 of parent form is clicked then child form will open inside the frame. Now what I need is when button 2 of child form is clicked then it should call the Button2_click
of the parent form.
Here is my parent form code:
public void MethodToExecute() //call this method
{
UPCCharges.Update();
if (HttpContext.Current.Session["CCost"] != null)
{
TxtCCost.Text = Session["CCost"].ToString();
}
DivCCharges.Visible = false;
IFMCCharge.Visible = false;
}
and this is Form 2 code:
protected void dgCFrom_ItemCommand(Object source, DataGridCommandEventArgs e)
{
UPCFromGrid.Update();
for (int vLoop2 = 0; vLoop2 < gvInner1.Items.Count; vLoop2++)
{
if (TxtTotalCFrom1 != null && TxtTotalCFrom2 != null)
{
TextBox TxtTotalCFrom = (TextBox)dgCFrom.Items[vLoop].FindControl("TxtTotalCFrom");
TextBox TxtTotalCYeild = (TextBox)dgCFrom.Items[vLoop].FindControl("TxtTotalCYeild");
Session["CCost"] = (mobjGenlib.ConvertDecimal(TxtTotalCFrom1.Text) + mobjGenlib.ConvertDecimal(TxtTotalCFrom2.Text)).ToString();
Session["CYeild"] = (mobjGenlib.ConvertDecimal(TxtRecoveryOrigin.Text) - mobjGenlib.ConvertDecimal(TxtTotalCFrom.Text)).ToString();
Session["CName"] = dgCFrom.Items[vLoop].Cells[1].Text;
Session["CJobID"] = HBLGeneralID;
}
}
}
FrmMasterSimulationChartNewUF frm = new FrmMasterSimulationChartNewUF();
frm.MethodToExecute();
}
The error I am getting is:
When keeping break point in the main form function MethodtoExecute
getting as Object reference not set to null. But from form1 if execute it was working with no error.
Can anyone please help me solve this?
Upvotes: 0
Views: 849
Reputation: 1541
Assuming here your "child" form is actually inside an iframe of the "parent" Form, and that both of these pages, are hosted on the same application and domain.
You can attach a javascript click event to Button2 of the child form to then invoke the click event of Button2 on the parent form using parent.document
E.g.
<button id="Button2" onclick="parent.document.getElementById('Button2').click();return false;">Child button 2</button>
Just beware of the actual ID values of your buttons , as they maybe changed due to UpdatePanels etc.
Upvotes: 0
Reputation: 3844
You should reference to master page
so add something like this line to your Contetnt page design:
<%@ MasterType VirtualPath="~/Site.master" %>
and try something like this:
var master = Master as SiteMaster;
SiteMaster mm = new SiteMaster();
mm.MethodToExecute();
master.MethodToExecute();
Let me know the feedback.
Upvotes: 1