This is my task . I have to create a master page and its two child pages. Details are below
Declare 3 session variables in master page.
Pages_viewed
ChildAppData1
ChildAppData2
Declare 1 session variable in each child application
ChildVar1
ChildVar2
Once the child application loads
Pages_viewed ++;
Set ChildVar1 = ChildAppData1 = datetime.now(); or ChildVar2 = ChildAppData2 = datetime.now();
Add a button to the master page that resets ALL variables.
Display all 5 variables in master page as well as active child application.
I have to show the no of times a child page is visited in page_viewed variable.
Simplest way is to Redirect to self with some information/command in the get parameter to self page.
like Default.master enclosing
Default.aspx
->Redirect to
`Default.aspx?cmd=clearAllVariables`
On Page_Load check
if(!PostBack && (Request["cmd"] != null) && (Request["cmd"].ToString() == "clearAllVariables"))
{
clearAllVariablesImplementation();
}
Related
I am using 'iFrame' on the website, and right now, whenever I directed to the another page (says Register Page) and I click F5 (Refresh button on the browser), it will go to the Default.aspx and not Register Page. I notice that while I directed to the Register Page or another Page, the url stays on: www.something.com/Default.aspx, but it should be www.something.com/Register.aspx. I think the cause for it cannot go back to the current page is because of the URL linked to the Default.aspx.
ID for Main Frame is MainFrame and here is the code:
if (Session["AFFM_RoleCode"] != null && Session["AFFM_RoleCode"].ToString() == "0")
{
// If the user is not logged in
if (Session["IsAgent"] != null && Session["IsAgent"].ToString() == "1")
{
mainFrame.Attributes["src"] = "BlankPage.aspx";
}
else
{
mainFrame.Attributes["src"] = "Main.aspx";
}
}
How do I can solve this problem?
Your answer much appreciated!
Thanks
This is a quick patch you can do to this, add a session to your register page when it load, such as
session["Load"] = "register";
and when the page is refreshed, if you find register in the load session, redirect it to the register
if (session["load"] == "register"){
session["load"] = "";
//you redirect code
}
I am trying to save the value in a session and then on page refresh, I am trying to use that value. But every time, it goes inside the loop .
I am using HttpContext.Current.Session because my class is inheriting from HTMLTable.
if (HttpContext.Current.Session["Id"] == null)
{
HttpContext.Current.Session["Id"] = "2";
}
string a = HttpContext.Current.Session["Id"].ToString(); //I get 2, WORKS HERE
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?
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.
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.
I have a Base Master Page where I set my title.
The problem is a few select pages need the title to come from a different source.
So I need to get a value from an ASP.NET literal and pass it to the Base Master Page in order to set the title.
Is this possible?
this is how my code looks in the CS code behind, but its still now getting to title from the content page
else if (PageID == 200|| PageID == 201 || PageID == 202 || PageID == 203)
{
ContentPlaceHolder cph =this.Master.FindControl("ContentPlaceHolder") as ContentPlaceHolder;
Label lit = cph.FindControl("ArtileTilte") as Label;
BrowserTitle = lit.Text;
}
Make a virtual property that retrieves the title in the base master page (this one contains the default behavior) and override it in the derived master page classes (this is where you define a different behavior - for example, getting the title from a literal). The link below contains an example of doing this:
http://msdn.microsoft.com/en-us/library/c8y19k6h(v=vs.100).aspx
Let's assume the control the holds the title is a Label, then in order to access the label on your master page do the following:
((Label)Master.FindControl("label")).Text = "My Title";
I have the following piece of code:
public abstract class BasePage : Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
if (IsPostBack)
return;
var section = ConfigurationManager.GetSection("UrlRewriter/PlainRules");
if (section == null)
SetMaster("~/App_Shared/Master/BaseRegular.Master");
else
SetMaster("~/App_Shared/Master/BaseRewritable.Master");
}
protected void SetMaster(string value)
{
MasterPage master = Master;
while (master != null)
{
if (master is SharedMaster)
{
master.MasterPageFile = value;
break;
}
master = master.Master;
}
}
}
It works great in changing my master pages dynamically, but I'd want to be able to do this directly from SharedMaster, rather than from every single page I have.
Page_PreInit doesn't ever fire if placed on the master page, so how can I accomplish this?
If you put this functionality in BasePage and then inherit each of your page from BasePage then you don't have to repeat the code in every page. You already seems to have a perfect working code.
As far as putting the logic in master page, it will not be possible - because once master page gets associated with the page and control tree is loaded, you cannot change the master page. The pre_init does not trigger for master page because master page is not loaded till that point and so once can change the master page associated with the page. Then master page is loaded and a composite control tree gets created and after that you will receive master page events.