如何在response.redirect(request.rawurl)之前显示我的文本标签 [英] How to display my text label before response.redirect(request.rawurl)

查看:69
本文介绍了如何在response.redirect(request.rawurl)之前显示我的文本标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示我的status_lbl文字标签



I'm trying to display my status_lbl text label before

Response.Redirect(Request.RawUrl);





我试过在重定向页面功能之前放置延迟时间,但它仍然没有显示status_lbl文本标签。









I've tried with putting delay time before the redirect page function, but still it doesn't show the status_lbl text label.



using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;
    using System.Web.Services;
    using System.Web.Script;
    using System.Web.Security;

    namespace TagNumberWeb
    {
    public partial class Main : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string CrUserID = Request.QueryString["LogInUser"].ToString();
            string Result = Request.QueryString["Result"].ToString();

            if (!IsPostBack)
            {
                if (string.IsNullOrWhiteSpace(CrUserID) || string.IsNullOrWhiteSpace(Result))
                {
                    Response.Redirect("Login Page.aspx");
                }

                else
                {                    
                    UserID.Text = Request.QueryString["LogInUser"].ToString();
                    status_lbl.Visible = false;
                    GridView1.Visible = false;
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string sONbr = sONbrTextBox.Text;
            string SOLine = sOLineTextBox.Text;
            string SerialNbr = serialNbrTextBox.Text;
            string StatusCode = statusCodeComboBox.Text;
            string CrUserID = Request.QueryString["LogInUser"].ToString();

            if (string.IsNullOrWhiteSpace(sONbr) || string.IsNullOrWhiteSpace(SOLine) || string.IsNullOrWhiteSpace(StatusCode) || string.IsNullOrEmpty(SerialNbr))
            {
                status_lbl.Text = "Please fill in all the information.";
                status_lbl.Visible = true;
                GridView1.Visible = false;
                return;
            }

            else if (string.IsNullOrWhiteSpace(CrUserID))
            {
                status_lbl.Text = "Please login your account!";
                status_lbl.Visible = true;
                ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Please login your account!')</script>");
                Response.Redirect("Login Page.aspx");
                GridView1.Visible = false;
                return;
            }

            else if (CheckBox1.Checked == true)
            {

                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constr_BCSystem"].ToString());
                conn.Open();

                SqlCommand comm = conn.CreateCommand();
                comm.CommandType = CommandType.StoredProcedure;
                comm.CommandText = "usp_TagNumberUpdate";

                comm.Parameters.AddWithValue("@sONbr", sONbr);
                comm.Parameters.AddWithValue("@SOLine", SOLine);
                comm.Parameters.AddWithValue("@SerialNbr", SerialNbr);
                comm.Parameters.AddWithValue("@StatusCode", StatusCode);
                comm.Parameters.AddWithValue("@CrUserID", CrUserID);

                SqlParameter ReturnVal = comm.Parameters.Add("@return", SqlDbType.NVarChar, 200);
                ReturnVal.Direction = ParameterDirection.Output;

                comm.ExecuteNonQuery();

                string val = (string)ReturnVal.Value;

                conn.Close();
                status_lbl.Text = val;
                status_lbl.Visible = true;
                Response.Redirect(Request.RawUrl);

            }

            else 
            {
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["constr_BCSystem"].ToString());
                conn.Open();

                SqlCommand comm = conn.CreateCommand();
                comm.CommandType = CommandType.StoredProcedure;
                comm.CommandText = "usp_TagNumberUpdateNoSN";

                comm.Parameters.AddWithValue("@sONbr", sONbr);
                comm.Parameters.AddWithValue("@SOLine", SOLine);
                comm.Parameters.AddWithValue("@StatusCode", StatusCode);
                comm.Parameters.AddWithValue("@CrUserID", CrUserID);

                SqlParameter ReturnVal = comm.Parameters.Add("@return", SqlDbType.NVarChar, 200);
                ReturnVal.Direction = ParameterDirection.Output;

                comm.ExecuteNonQuery();

                string val = (string)ReturnVal.Value;

                conn.Close();
                status_lbl.Text = val;
                status_lbl.Visible = true;
                Response.Redirect(Request.RawUrl);
            }
        }

推荐答案

试试这个:

Try this:
Label1.Text = "Redirecting to Page 2";
ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "setTimeout(function(){location.href='Default2.aspx';},5000);", true);



我刚认为settimeout可以在这里得到很好的使用。


I have just thought that the settimeout could be put to good use here.


Hai



你需要显示标签文字的目的是什么?实际上你指定val来标记文本并将其更改为true,那么你在哪里显示标签?你试着检查标签文本中的val传递吗?你需要找到val字符串中出现的值吗?



实际上你在标签文本中指定值并将visible设置为true。它也会显示标签,但下一行你会重定向到另一个页面,所以你看不到标签文字。所以试着评论重定向行,然后只看你看标签。



OK试试这个,首先在脚本中添加这个



Hai

what purpose u need to show label text ? actually u assign val to label text and change visible as true,so where u show label ? u try to check val pass in label text or not ? u need to find what value appear in val string ??

Actually u assign value in label text and also set visible as true. it will also visible label,but next line u redirect to another page so u cant see label text.So try to comment redirect line then only u see label.

OK try this,first add this in script

  function testmsg(msg) {
alert(msg);
}





在重定向页面之前添加此行





Add this line before redirect page

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "<script type='text/javascript'>testmsg('" + val + "');</script>", false);





u延迟页面重定向或无法在文本框或标签文本中显示,请尝试在警告信息中显示。



u cant delay page redirect or cant show in textbox or label text,try show in alert msg.


您可以尝试Peter的解决方案。



另一种选择可能是在第二页上显示标签,这是最理想和最现代的方法。
You can try Peter's solutions.

Another alternative could be showing a Label on the second page, which is the most desired and modern approach.


这篇关于如何在response.redirect(request.rawurl)之前显示我的文本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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