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

  • Question

  • [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>
    


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

    Friday, July 7, 2017 12:10 PM

All replies

  • 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


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Monday, July 10, 2017 3:05 AM