Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从void方法输出变量,以便javascript函数可以读取它_C#_Asp.net - Fatal编程技术网

C# 从void方法输出变量,以便javascript函数可以读取它

C# 从void方法输出变量,以便javascript函数可以读取它,c#,asp.net,C#,Asp.net,您好,我正在尝试通过此方法对用户进行身份验证 protected void btnLogin_Click(object sender, EventArgs e) { string email = txtEmail.Text; string password = txtPassword.Text; try { bool loginResult = SingletonManager.Instance.F

您好,我正在尝试通过此方法对用户进行身份验证

protected void btnLogin_Click(object sender, EventArgs e)
    {
        string email = txtEmail.Text;
        string password = txtPassword.Text;

        try
        {
            bool loginResult = SingletonManager.Instance.FrontendFactories.UserFrontendFactory.LoginUser(email, FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "MD5"), chkRememberMe.Checked);
            if (loginResult == true)
            {
                FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, true);
                Context.Items.Add("email", txtEmail.Text);
            }
            else
            {
                txtEmail.CssClass += " " + "txt-error-message";
                errorIconmaEmail.Visible = true;
                txtPassword.CssClass += " " + "txt-error-message";
                errorIconPassword.Visible = true;
            }
        }
        catch (Exception ex)
        {
            lblerror.Text = ex.Message;
        }
    }
现在我知道它是一个void方法,void方法不返回值,但是有没有解决方法可以在else块(而不是当前代码)中创建bool,例如bool isValidUser=false,因此javascript函数将根据这个bool的值处理错误消息样式。仅供参考,我正在访问公共变量thorugh背后的代码

<%= isValidUser %>

似乎就是您要寻找的功能