Asp.net中的多用户问题 [英] Multiuser problem in Asp.net

查看:53
本文介绍了Asp.net中的多用户问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

在这里,我在应用程序中使用了公共静态字符串A; 变量.
假设user1拥有A ="1",现在user2变为这种形式,他的A = 2.
因此,在这种情况下,user1(即A = 1)的A原始值替换为user2(现在是A = 2),但是我想同时保留两个用户的两个值..

注意:
1)我使用了公共字符串A; ,但是在回发期间它失去了它的值.

我不想为此使用会话变量.

供参考的示例编码部分->

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"));
        }
    }




任何帮助都将得到高度重视....
谢谢.

解决方案

为什么不将值A保留在视图状态中,而将更新面板用于异步回发. >

为什么不能在ViewReport()例程中直接使用"Rdbtn.SelectedValue".

 如果(Rdbtn.SelectedValue == " )
{
    crystalReport.Load(Server.MapPath(" )));
}
其他 如果(Rdbtn.SelectedValue == "  2")
{
    crystalReport.Load(Server.MapPath(" )));
}



然后我们可以尝试的另一种方法是使用Switch Case;这是提高性能的更好方法.

[更新]:我没有注意到您在代码中使用了公共静态字符串_print;这是为了什么?那里存在一些逻辑错误;我相信.




如果我错了,请纠正我.您尝试使用隐藏字段吗?

<asp:HiddenField ID="hdnValue" runat="server" Value="Secret Value" />



这样,您就可以将变量设置为公共字符串A.
在分配字符串变量的同时分配隐藏变量.
在回发时,使用隐藏变量重新分配字符串变量.

希望这会有所帮助.


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.

解决方案

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


Why can''t you use "Rdbtn.SelectedValue" directly in the ViewReport() routine.

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.


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.


这篇关于Asp.net中的多用户问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆