在后退按钮窗口中如何设置标签可见false [英] In back button window how to set label visible false

查看:74
本文介绍了在后退按钮窗口中如何设置标签可见false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的运行模式如下





Detailspage如下



Empid 10001



手机9784000002



提交(按钮)



当我给出正确的Empid和Mobile时,它会在新的标签窗口中重定向到注册页面。



在浏览器的新标签窗口中我按回(< ;-) arrow它会去detailspage.aspx。



然后当我输入错误的Empid和Mobile时,它会在label1中显示消息为您的数据不匹配。





然后用户输入正确的Empid和Mobile,它会在新的标签窗口中重定向到注册页面。



在新标签窗口中,在浏览器中,当我按下(< ;-)箭头时,它将显示为Detailspage.aspx。在那个detailspage.aspx之前显示标签1中的消息

您的数据不匹配。该消息设置为可见假。









提交按钮代码如下





protected void btnsubmit_Click(object sender,EventArgs e)

{

SqlConnection con = new SqlConnection();

con.ConnectionString =Data Source = .\\SQLEXPRESS; Initial Catalog = test; Integrated Security = True;

string query =select * from login where Empid ='+ txtempid.text +'and mobile ='+ txtmobile.text +';

SqlCommand cmd = new SqlCommand(query,con);

con.open();

SqlDataAdapter da = new SqlDataAdapter(cmd);

Datatable dt = new datatable();

da.Fill(dt);

if(dt.Rows.Count> 0)

{



Response.Redirect(Detailspage.aspx);

label.visible = false;

}



其他

{

label1.text =您的数据不合适ch;

}



}





但是当我运行代码时,label1不可见false。当它重定向到Details.aspx页面。



请帮我解决上面代码中的错误。



我尝试了什么:



当我提供正确的Empid和Mobile时,它会在新的标签窗口中重定向到注册页面。



在浏览器的新选项卡窗口中,当我按回(< ;-)箭头时,它将转到detailspage.aspx。



然后当我输入错误的Empid和Mobile时,它会将label1中的消息显示为您的数据不匹配。





然后用户输入正确的Empid和Mobile,它会在新的标签窗口中重定向到注册页面。



在新标签窗口中,在浏览器中,当我按下(< ;-)箭头时,它将显示为Detailspage.aspx。在那个detailspage.aspx之前显示标签1中的消息

您的数据不匹配。该消息设置为可见false。

My run mode as follows


Detailspage as follows

Empid 10001

Mobile 9784000002

Submit (Button)

When i give the correct Empid and Mobile it redirects to Registration page in a new tab window.

In that New tab window in browser when i press back (<-) arrow it will go detailspage.aspx.

Then again when i enter wrong Empid and Mobile it shows the message in the label1 as "Your Data does not match".


Then user enter the correct Empid and Mobile it redirects to Registration page in a new tab window.

In that New tab window, in browser when i press back (<-) arrow it will go Detailspage.aspx. in that detailspage.aspx previously shows the message in the label1
"Your Data does not match". that message to set visible false.




In submit button code as follows


protected void btnsubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString="Data Source=.\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True;"
string query = "select * from login where Empid= '" + txtempid.text + "' and mobile = '" + txtmobile.text + "'";
SqlCommand cmd = new SqlCommand(query,con);
con.open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
Datatable dt = new datatable();
da.Fill(dt);
if(dt.Rows.Count > 0)
{

Response.Redirect("Detailspage.aspx");
label.visible = false;
}

else
{
label1.text = "Your Data does not match";
}

}


But when i run the code the label1 is not visible false. when it redirects to Details.aspx page.

Please help me what is the mistake in my above code.

What I have tried:

When i give the correct Empid and Mobile it redirects to Registration page in a new tab window.

In that New tab window in browser when i press back (<-) arrow it will go detailspage.aspx.

Then again when i enter wrong Empid and Mobile it shows the message in the label1 as "Your Data does not match".


Then user enter the correct Empid and Mobile it redirects to Registration page in a new tab window.

In that New tab window, in browser when i press back (<-) arrow it will go Detailspage.aspx. in that detailspage.aspx previously shows the message in the label1
"Your Data does not match". that message to set visible false.

推荐答案

代码运行正常,因为当发生回发时,框架记住页面状态,即标签可见性= true或false,具体取决于单击按钮时的逻辑。因此,如果您的代码使其可见,则单击后退按钮仅在用户离开时重新加载页面,它不会自动执行用户的任何按钮单击。



这是任何浏览器和.net的默认功能。



如果你想让用户在点击后退按钮然后提交时看到不同的标签首先,设置一个会话变量来识别点击的提交。

然后在页面上加载检查会话变量以查看用户是否点击了后退按钮。

例如你可以保存TimeStamp或用户点击提交时的日期时间,并检查它是否在页面加载时过去。
The code is working perfectly because when a postback occurs, the framework "remembers" the state of the page which is label visibility = true or false depending on the logic when button was clicked. So if your code is making it visible, clicking back button only re-loads the page as the user left it, it doesn't automagically execute any button clicks for the user.

This is the default function of any browser and .net.

if you want to make the user see a different label when they click back button then on submit in first place, set a session variable to identify the submit clicked.
then on page load check the session variable to see if the user clicked back button.
For example you could save the TimeStamp or datetime of when the user clicks on submit and check if it is in the past on page load.


这篇关于在后退按钮窗口中如何设置标签可见false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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