Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends,

Here, i've used public static string A; variable in my application.
Suppose, user1 hav A="1" and now user2 come to this form and he has A=2.
So, in this case original value of A for user1(which is A=1) replaced with user2(which is now A=2), But i want to keep both of the value saprately for both the users..

Note :
1) i used public string A; but during postback it lost its value.

i dont want to use session variable for this.

sample coding part for reference-->

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;

public partial class PO_REG : System.Web.UI.Page
{
   
    public static string A; 
    public static string _print; 
    public void Page_Init(object sender, EventArgs e)
    {
        if (_print == "P")
        {
            ViewReport();
        }
    }
       #endregion

    protected void btnShowReport_Click(object sender, ImageClickEventArgs e)
    {
        _print = "P";
        A = Rdbtn.SelectedValue;        
        ViewReport()
    }

    private void ViewReport()
    {
        ReportDocument crystalReport = new ReportDocument();
        if (A == "1")
        {
            crystalReport.Load(Server.MapPath("sample1.rpt"));
        }
        else if (A == "2")
        {
            crystalReport.Load(Server.MapPath("sample2.rpt"));
        }
    }



any help would be highly appriciated....
thank you.
Posted
Updated 4-Nov-12 23:06pm
v7

Why not to hold the value A in a viewstate and use update panels for asynchronous post backs. it will be much helpful in multi user applications
 
Share this answer
 
Comments
Vikas_Shukla_89 5-Nov-12 5:27am    
Thanks dear for reply..
but im not using ajax.
Why can't you use "Rdbtn.SelectedValue" directly in the ViewReport() routine.

C#
if (Rdbtn.SelectedValue == "1")
{
    crystalReport.Load(Server.MapPath("sample1.rpt"));
}
else if (Rdbtn.SelectedValue == "2")
{
    crystalReport.Load(Server.MapPath("sample2.rpt"));
}


Then another thing we can try is using switch Case; which is a better way to increase the performance.

[Update]: I didnt noticed you have used public static string _print in the code ; whats it for? Some logical mistake is there; I beleive.
 
Share this answer
 
v3
Comments
Vikas_Shukla_89 5-Nov-12 5:05am    
Bcoz, when user clicks print button in crystal reportviewer then it will fire Page_init event of page.. so, its value for (Rdbtn.SelectedValue) will not there. it will show you null value only..
Ankur\m/ 5-Nov-12 5:13am    
Then another thing we can try is using switch Case; which is a better way to increase the performance
I disagree. For just 2 conditional statements, there won't be any difference. Switch cases are good from readability perspective as well but if there are few conditional statements, if-else is just fine.
Vikas_Shukla_89 5-Nov-12 5:15am    
yeah.. ri8
Baji Jabbar 5-Nov-12 5:30am    
:thumbsup:
For sure Switch Case is better way than if else conditions not only for readability but for performance too. Yeah for few conditional statements we cant notice any difference
Vikas_Shukla_89 5-Nov-12 5:14am    
if (_print == "P"){ViewReport();}
Well, this is for, i want to run this code only if user have already clicked on the asp:button --> ShowReport, otherwise not. dat is y..
Hi,

Correct me if i am wrong.Did you try usng hidden field?
<asp:HiddenField ID="hdnValue" runat="server" Value="Secret Value" />


In that way you can make your variable as public string A.
Assign the hidden variable while assigning the string variable.
On Postback reassign the string variable using the hidden variable.

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900