soniya soniya - 2 months ago 16
ASP.NET (C#) Question

get data from two different pages

Here is my problem. suppose by example, when I click on repeater row id then it will transfer to particular customers invoice.

But in customer invoice page, it opens only when customer Id logged in. So here two different pages accessing one page data. my code is as below.
In repeater's page.

<th>
<asp:LinkButton ID ="lnkbtnStmt" Text ="Statement" OnClick ="lnkbtnStmt_Click" runat="server"></asp:LinkButton>
<asp:HiddenField ID ="hfStmt" runat ="server" Value='<% #Eval("No")%>'/>
</th>


in repeater .cs page :

public void lnkbtnStmt_Click(object sender, EventArgs e)
{
int rptIndex = ((RepeaterItem)((LinkButton)sender).NamingContainer).ItemIndex;
string hfItem = Convert.ToString(((HiddenField)RptEmpCustInvoise.Items[rptIndex].FindControl("hfStmt")).Value);

Customer_Ledger_Entries custlist = new Customer_Ledger_Entries();
List<Customer_Ledger_Entries_Filter> cFilter = new List<Customer_Ledger_Entries_Filter>();
Customer_Ledger_Entries_Filter cfield = new Customer_Ledger_Entries_Filter();
cfield.Field = Customer_Ledger_Entries_Fields.Customer_No;
cfield.Criteria = hfItem;
cFilter.Add(cfield);
Customer_Ledger_Entries[] culist = cls.wsCustInvoice.ReadMultiple(cFilter.ToArray(), null, 1);
if (culist.Length > 0)
{
Response.Redirect("frmCustomerInvoice.aspx?Customer_No=" + hfItem);
}
}


And in another Customer page.

protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
GetOpeningBal();
bindCustInvoice(objSession.getSession(HttpContext.Current, "NonEmpCode"));
string empCustId = Request.QueryString["Customer_No"];
if (empCustId.Length != 0)
{
CustInvoice("empCustId");
}
GetClosingBal();

}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), string.Empty, "alert('" + ex.Message.ToString() + "');", true);
}
}


In this page,
bindCustInvoice()
method works when customer get logged in and
CustInvoice("empCustId");
method works when we clicked on repeater id.
can any one give me solution?

Answer

When you clicked on Repeater Id , try to send the Page Name from Query String . and check the page name in your another customer page

Pseudo code

 string PageName ="";
      if(Request.QueryString["PageName"] != null)
      {
       PageName= Request.QueryString["PageName"];
      }


    if(PageName != "")
    {
     string empCustId = Request.QueryString["Customer_No"];
                    if (empCustId.Length != 0)
                    {
                        CustInvoice("empCustId");
                    }
    }
    else{
      bindCustInvoice(objSession.getSession(HttpContext.Current, "NonEmpCode"));
    }