[C#] [ASP.NET] [WebForm]如何避免屏幕闪烁? [英] [C #][ASP.NET][WebForm] How to avoid the screen flash?

查看:103
本文介绍了[C#] [ASP.NET] [WebForm]如何避免屏幕闪烁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[C#] [ASP.NET] [WebForm]如何避免屏幕闪烁?
$


Q1选举一次,Q2不能编辑;

Q1选举B,Q2可以编辑;

因为是PostBack,点击屏幕会闪烁。

(原始网页)是一个更复杂的网页,我剪出两个字段来制作一个小程序,所以它可能看不到闪光的情况)



问题1:想要使用前端JavaScript解决了flash的情况,但我看看HTML Source,这似乎已经是一个JavaScript了? (或者不是?)

问题2:有没有一种方法可以避免这个问题的闪烁?非常感谢。

<%@ Page Language =" C#" AutoEventWireup = QUOT;真"代码隐藏= QUOT; Default.aspx.cs"继承= QUOT; WebApplication5.Default" %GT; 

<!DOCTYPE html>
< html xmlns =" http://www.w3.org/1999/xhtml">
< head runat =" server">
< meta http-equiv =" Content-Type"含量=" text / html的;字符集= UTF-8英寸/>
< title>< / title>
< / head>
< body>
< form id =" form1" RUNAT = QUOT;服务器">
< asp:SqlDataSource ID =" SqlDataSource1" RUNAT = QUOT;服务器" ConnectionString ="<%$ ConnectionStrings:TestDBConnectionString%>"
InsertCommand =" INSERT INTO [Table2]([Q1],[Q2])VALUES(@ Q1,@ Q2)"
SelectCommand =" SELECT * FROM [Table2]">
< InsertParameters>
< asp:参数名称=" Q1"类型="字符串" />
< asp:参数名称=" Q2"类型="字符串" />
< / InsertParameters>
< / asp:SqlDataSource>
< asp:DetailsView ID =" DetailsView1" RUNAT = QUOT;服务器"高度= QUOT; 50像素"宽度= QUOT; 125px"
DefaultMode =" Insert"
AutoGenerateRows =" False"的DataKeyNames = QUOT;否]的DataSourceID = QUOT; SqlDataSource1">
< Fields>
< asp:BoundField DataField =" no"的HeaderText = QUOT;否] InsertVisible = QUOT假QUOT;只读= QUOT;真"的SortExpression = QUOT;否] />
< asp:TemplateField HeaderText =" Q1"的SortExpression = QUOT; Q1">
< InsertItemTemplate>
< asp:RadioButtonList RepeatDirection =" Horizo​​ntal"
ID =" RadioButtonList1" RUNAT = QUOT;服务器"的AutoPostBack = QUOT;真"
OnSelectedIndexChanged =" RadioButtonList1_SelectedIndexChanged">
< asp:ListItem> A< / asp:ListItem>
< asp:ListItem> B< / asp:ListItem>
< / asp:RadioButtonList>
< / InsertItemTemplate>
< ItemTemplate>
< asp:Label ID =" Label1" RUNAT = QUOT;服务器" Text ='<%#Bind(" Q1")%>'>< / asp:Label>
< / ItemTemplate>
< / asp:TemplateField>
< asp:TemplateField HeaderText =" Q2"的SortExpression = QUOT; Q2">
< InsertItemTemplate>
< asp:TextBox ID =" TextBox_Q2" RUNAT = QUOT;服务器" Text ='<%#Bind(" Q2")%>'>< / asp:TextBox>
< / InsertItemTemplate>
< ItemTemplate>
< asp:Label ID =" Label2" RUNAT = QUOT;服务器" Text ='<%#Bind(" Q2")%>'>< / asp:Label>
< / ItemTemplate>
< / asp:TemplateField>
< asp:CommandField ShowEditButton =" True" />
< / Fields>
< / asp:DetailsView>
< / form>
< / body>
< / html>



使用System; 
使用System.Web.UI.WebControls;

名称空间WebApplication5
{
公共部分类默认值:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
}

protected void RadioButtonList1_SelectedIndexChanged(object sender,EventArgs e)
{
RadioButtonList RadioButtonList1 =(RadioButtonList)DetailsView1.FindControl(" RadioButtonList1" );
TextBox TextBox_Q2 =(TextBox)DetailsView1.FindControl(" TextBox_Q2");
if(RadioButtonList1.SelectedValue ==" A")
{
TextBox_Q2.Enabled = false;
}
if(RadioButtonList1.SelectedValue ==" B")
{
TextBox_Q2.Enabled = true;
}
}
}
}

HTML源

 
<!DOCTYPE html>
< html xmlns =" http://www.w3.org/1999/xhtml">
< head>< meta http-equiv =" Content-Type"含量=" text / html的;字符集= UTF-8英寸/><标题>

< / title>< / head>
< body>
< form method =" post"行动= QUOT; ./ Default.aspx的" ID = QUOT; form1的">
< div class =" aspNetHidden">
< input type =" hidden"名称= QUOT; __ EVENTTARGET" ID = QUOT; __ EVENTTARGET"值= QUOT;" />
< input type =" hidden"名称= QUOT; __ EVENTARGUMENT" ID = QUOT; __ EVENTARGUMENT"值= QUOT;" />
< input type =" hidden"命名= QUOT; __ LASTFOCUS" ID = QUOT; __ LASTFOCUS"值= QUOT;" />
< input type =" hidden"命名= QUOT; __ VIEWSTATE" ID = QUOT; __ VIEWSTATE"值= QUOT; / fLCtSdJ9kKujCihhKEnS + MI + EmtlwwayVIo2WpUwiwAeBLIGaZR0VagYdNqIcYhNZcMnlr4MM6sxa3F61SsQkfzf5wdlXGKgOUnl4OyVuEirF /小时+ h78jpTcUGpZMaPPWHKNVsXko / GmZ0ac57NjY7Gs2foAirrt3LE3nUuIE + PpUCrt7novxYiG4a7NsyqzGlcNhjR / zrvcAlQj1d52a8pQ0MNq0pjsYdhkFCF0Fn / UnxczobhvIguiD8gDtfgi0lvfEg6VSIqP8FzgggrT5L / KwwsLoJCkSrB83LQGlTKSoQAp / ULkWJV4JSaYMcD" />
< / div>

< script type =" text / javascript">
//<![CDATA [
var theForm = document.forms ['form1'];
if(!theForm){
theForm = document.form1;
}
函数__doPostBack(eventTarget,eventArgument){
if(!theForm.onsubmit ||(theForm.onsubmit()!= false)){
theForm .__ EVENTTARGET.value = eventTarget;
theForm .__ EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
< / script>



< div>
< table cellspacing =" 0"规则= QUOT;所有"边界=" 1 QUOT; ID = QUOT; DetailsView1"风格= QUOT;高度:50像素;宽度:125px;边界崩溃:崩溃;">
< tr>
< td> Q1< / td>< td>
< table id =" DetailsView1_RadioButtonList1">
< tr>
< td>< input id =" DetailsView1_RadioButtonList1_0"类型= QUOT;无线电"名称= QUOT; DetailsView1 $ RadioButtonList1"值= QUOT; A"的onclick = QUOT;的javascript:的setTimeout(安培;#39; __ doPostBack(\&安培;#39; DetailsView1 $ RadioButtonList1 $ 0\&安培;#39;,\&安培;#39; \&安培;#39;)及;#39;,0)" />< label for =" DetailsView1_RadioButtonList1_0"> A< / label>< / td>< td>< input id =" DetailsView1_RadioButtonList1_1"类型= QUOT;无线电"名称= QUOT; DetailsView1 $ RadioButtonList1"值= QUOT; B"的onclick = QUOT;的javascript:的setTimeout(安培;#39; __ doPostBack(\&安培;#39; DetailsView1 $ RadioButtonList1 $ 1\&安培;#39;,\&安培;#39; \&安培;#39;)及;#39;,0)" />< label for =" DetailsView1_RadioButtonList1_1"> B< / label>< / td>
< / tr>
< / table>
< / td>
< / tr>< tr>
< td> Q2< / td>< td>
< input name =" DetailsView1 $ TextBox_Q2"类型= QUOT;文本" ID = QUOT; DetailsView1_TextBox_Q2" />
< / td>
< / tr>< tr>
< td colspan =" 2">< / td>
< / tr>
< / table>
< / div>

< div class =" aspNetHidden">

< input type =" hidden"名称= QUOT; __ VIEWSTATEGENERATOR" ID = QUOT; __ VIEWSTATEGENERATOR"值= QUOT; CA0B0334" />
< input type =" hidden"命名= QUOT; __ VIEWSTATEENCRYPTED" ID = QUOT; __ VIEWSTATEENCRYPTED"值= QUOT;" />
< input type =" hidden"名称= QUOT; __ EVENTVALIDATION" ID = QUOT; __ EVENTVALIDATION"值= QUOT; kY7fZEkW3D + wRbCQqvA7YJVcGcgn1ELkV1lFZIG9yD6a5 / HJ3 / Z3DCL8BGbO3rcRUyB3G0H8mbElGCKBYIINdvqnqyAEwKWHbBkJdMDAiUrkrno8TUeVnKJmED3da9KVcnLiwgow0GU4SgiKbmqSCLvfZpWUkZOw4TGOUBtIQBf1tBRnY3bL06aSyjlOHvtt" />
< / div>< / form>

<! - Visual Studio浏览器链接 - >
< script type =" application / json" ID = QUOT; __ browserLink_initializationData">
{" appName":" Internet Explorer"," requestId":" 811cd046574349198305b0d06de62b63"}
< / script>
< script type =" text / javascript" SRC =" HTTP://本地主机:1668 / 7fc165c4f9924515b70b918989088ed6 / browserLink"异步= QUOT;异步">< /脚本>
<! - 终端浏览器链接 - >

< / body>
< / html>






********************孔子说:问有三种不懂则问;虽懂而有疑惑则问;虽懂而想更了解则问; ********************

解决方案

Hi luicst,


欢迎来到MSDN论坛。


参考你的描述,您的问题是关于ASP.NET Web Forms应用程序开发。由于我们的论坛是讨论Visual Studio WPF / SL设计器,Visual
工作室指导自动化工具包,开发人员文档和帮助系统以及Visual Studio编辑器,请重定向到这个适当的论坛:
https://forums.asp.net/18.aspx/1?Web+Forms 并开始新的主题寻求更专业的支持,谢谢你的理解。


祝你有愉快的一天。



< p style ="margin-bottom:12pt">



最好的问候,


萨拉


[C #][ASP.NET][WebForm] How to avoid the screen flash?

Q1 election A time, Q2 can not be edited;
Q1 election B, Q2 can be edited;
Because it is PostBack, click the screen will flash.
(The origion webpage is a more complex webpage, I cut out two fields to make a small program, so it maybe not see the flash of the situation)

Question 1: want to use front-end JavaScript to solve the flash situation, but I look at HTML Source, which seems to be already a JavaScript? (Or not?)
Question 2: Is there a good way to avoid flashing for this problem? Thank you very much.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication5.Default" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>"
            InsertCommand="INSERT INTO [Table2] ([Q1], [Q2]) VALUES (@Q1, @Q2)"
            SelectCommand="SELECT * FROM [Table2]">
            <InsertParameters>
                <asp:Parameter Name="Q1" Type="String" />
                <asp:Parameter Name="Q2" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
        <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px"
            DefaultMode="Insert"
            AutoGenerateRows="False" DataKeyNames="no" DataSourceID="SqlDataSource1">
            <Fields>
                <asp:BoundField DataField="no" HeaderText="no" InsertVisible="False" ReadOnly="True" SortExpression="no" />
                <asp:TemplateField HeaderText="Q1" SortExpression="Q1">
                    <InsertItemTemplate>
                        <asp:RadioButtonList RepeatDirection="Horizontal"
                            ID="RadioButtonList1" runat="server" AutoPostBack="true"
                            OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                            <asp:ListItem>A</asp:ListItem>
                            <asp:ListItem>B</asp:ListItem>
                        </asp:RadioButtonList>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Q1") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Q2" SortExpression="Q2">
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox_Q2" runat="server" Text='<%# Bind("Q2") %>'></asp:TextBox>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Q2") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowEditButton="True" />
            </Fields>
        </asp:DetailsView>
    </form>
</body>
</html>


using System;
using System.Web.UI.WebControls;

namespace WebApplication5
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            RadioButtonList RadioButtonList1 = (RadioButtonList)DetailsView1.FindControl("RadioButtonList1");
            TextBox TextBox_Q2 = (TextBox)DetailsView1.FindControl("TextBox_Q2");
            if (RadioButtonList1.SelectedValue == "A")
            {
                TextBox_Q2.Enabled = false;
            }
            if (RadioButtonList1.SelectedValue == "B")
            {
                TextBox_Q2.Enabled = true;
            }
        }
    }
}

HTML Source

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>

</title></head>
<body>
    <form method="post" action="./Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/fLCtSdJ9kKujCihhKEnS+Mi+EmtlwwayVIo2WpUwiwAeBLIGaZR0VagYdNqIcYhNZcMnlr4MM6sxa3F61SsQkfzf5wdlXGKgOUnl4OyVuEirF/Ih+h78jpTcUGpZMaPPWHKNVsXko/GmZ0ac57NjY7Gs2foAirrt3LE3nUuIE+PpUCrt7novxYiG4a7NsyqzGlcNhjR/zrvcAlQj1d52a8pQ0MNq0pjsYdhkFCF0Fn/UnxczobhvIguiD8gDtfgi0lvfEg6VSIqP8FzgggrT5L/KwwsLoJCkSrB83LQGlTKSoQAp/ULkWJV4JSaYMcD" />
</div>

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
    theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = eventTarget;
        theForm.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
}
//]]>
</script>


        
        <div>
	<table cellspacing="0" rules="all" border="1" id="DetailsView1" style="height:50px;width:125px;border-collapse:collapse;">
		<tr>
			<td>Q1</td><td>
                        <table id="DetailsView1_RadioButtonList1">
				<tr>
					<td><input id="DetailsView1_RadioButtonList1_0" type="radio" name="DetailsView1$RadioButtonList1" value="A" onclick="javascript:setTimeout(&#39;__doPostBack(\&#39;DetailsView1$RadioButtonList1$0\&#39;,\&#39;\&#39;)&#39;, 0)" /><label for="DetailsView1_RadioButtonList1_0">A</label></td><td><input id="DetailsView1_RadioButtonList1_1" type="radio" name="DetailsView1$RadioButtonList1" value="B" onclick="javascript:setTimeout(&#39;__doPostBack(\&#39;DetailsView1$RadioButtonList1$1\&#39;,\&#39;\&#39;)&#39;, 0)" /><label for="DetailsView1_RadioButtonList1_1">B</label></td>
				</tr>
			</table>
                    </td>
		</tr><tr>
			<td>Q2</td><td>
                        <input name="DetailsView1$TextBox_Q2" type="text" id="DetailsView1_TextBox_Q2" />
                    </td>
		</tr><tr>
			<td colspan="2"></td>
		</tr>
	</table>
</div>
    
<div class="aspNetHidden">

	<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="CA0B0334" />
	<input type="hidden" name="__VIEWSTATEENCRYPTED" id="__VIEWSTATEENCRYPTED" value="" />
	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="kY7fZEkW3D+wRbCQqvA7YJVcGcgn1ELkV1lFZIG9yD6a5/HJ3/Z3DCL8BGbO3rcRUyB3G0H8mbElGCKBYIINdvqnqyAEwKWHbBkJdMDAiUrkrno8TUeVnKJmED3da9KVcnLiwgow0GU4SgiKbmqSCLvfZpWUkZOw4TGOUBtIQBf1tBRnY3bL06aSyjlOHvtt" />
</div></form>

<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
    {"appName":"Internet Explorer","requestId":"811cd046574349198305b0d06de62b63"}
</script>
<script type="text/javascript" src="http://localhost:1668/7fc165c4f9924515b70b918989088ed6/browserLink" async="async"></script>
<!-- End Browser Link -->

</body>
</html>


******************** 孔子說:問有三種 不懂則問; 雖懂而有疑惑則問; 雖懂而想更了解則問; ********************

解决方案

Hi luicst,

Welcome to the MSDN forum.

Refer to your description, your issue is about the ASP.NET Web Forms application development. Since our forum is to discuss the Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor, please redirect to this appropriate forum: https://forums.asp.net/18.aspx/1?Web+Forms and start a new thread to seek for a more professional support, thank you for your understanding.

Have a nice day.

Best regards,

Sara


这篇关于[C#] [ASP.NET] [WebForm]如何避免屏幕闪烁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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