如何防止我的项目中的标题回发?我不想刷新每个问题的标题 [英] How to prevent post back for header in my project ? i dont want to refresh the header for every question

查看:45
本文介绍了如何防止我的项目中的标题回发?我不想刷新每个问题的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Language="C#" MasterPageFile="~/OnlineExam/ExamMaster.master" AutoEventWireup="true" CodeFile="StartExam.aspx.cs" Inherits="StartExam" %>

<%--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">--%>


<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <head>
    <title>Online Examination</title>
     <script type="text/javascript" language="javascript">
         function fun1() {
             alert("TimeOut!");
             window.location = "Result.aspx";
         }
</script>
</head>

    <body>
    <form id="form1">
    <asp:ScriptManager ID="ScriptManager1" runat="server"/>
    <div>

      <table align="right">
        <tr>
        <td>
        <asp:Timer ID="tim1" runat="server" OnTick="Timer1_Tick" Interval="1000"

        Enabled="False"  ></asp:Timer>

      <asp:UpdatePanel ID="up1" runat ="server" UpdateMode="Conditional" >
         <ContentTemplate>
          <asp:Label ID="label_time" runat="server" ></asp:Label>
         </ContentTemplate>
        <Triggers>
         <asp:AsyncPostBackTrigger ControlID="tim1" EventName="Tick"/>
        </Triggers>
      </asp:UpdatePanel>
        </td>
        </tr>
        </table>

    <table align="center">
    <tr>
    <td>
    Welcome&nbsp;
         <asp:Label ID="lblname" runat="server"></asp:Label>
        <br/>
    Subject:
        <asp:Label ID="lblsub" runat="server"></asp:Label>
        <br/>

    </td>
    </tr>
    </table>


    <table>
    <tr>
     <td style="width: 97px">

        <asp:Label ID="lblqno" runat="server"></asp:Label>

        <asp:Label ID="lblQue" runat="server"></asp:Label>
        <br />
        <asp:RadioButtonList ID="rbtl" runat="server"

            onselectedindexchanged="rbtl_SelectedIndexChanged" >
           <asp:ListItem Text ="" Value ="Rd1" > </asp:ListItem>
           <asp:ListItem Text ="" Value ="Rd2"> </asp:ListItem>
           <asp:ListItem Text ="" Value ="Rd3"> </asp:ListItem>
           <asp:ListItem Text ="" Value ="Rd4"> </asp:ListItem>
        </asp:RadioButtonList>

&nbsp;<asp:LinkButton ID="lnkNxt" runat="server" onclick="lnkNxt_Click"

             ForeColor="#FF66CC" style="font-size:medium" Width="82px"><h2>Next</h2></asp:LinkButton>
         &nbsp;&nbsp;

        <asp:Panel ID="pnl" runat="server" style="color:red">
        </asp:Panel>
        <br />
        <asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click"

            Text="Submit" Visible="False" />
            </td>
           </tr>
      </table>

    </div>

    </form>
</body>

</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

</asp:Content>

<%--</html>--%>

推荐答案

如果您只想刷新页面的一部分而不是全部,那么您需要查看异步方法,如AJAX / JSON:





初学者的Ajax教程:第1部分 [ ^ ]



和:



Ajax教程XML和XML初学者JSON:第2部分 [ ^ ]
If you only want to refresh a part of the page rather than all of it, then you need to look at asynchronous methods such as AJAX/JSON:


Ajax Tutorial for Beginners: Part 1[^]

and:

Ajax Tutorial for Beginners with XML & JSON: Part 2[^]


<asp:UpdatePanel ID="up1" runat ="server" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label ID="label_time" runat="server" ></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tim1" EventName="Tick"/>
</Triggers>
</asp:UpdatePanel>





您使用的上述代码将仅更新更新面板中包含的内容。更改问题的控件(下一个按钮)位于此更新面板之外。因此,这会导致回发更新所有内容。您应该在此更新面板中包装要异步更新的内容,或者您​​可以使用其他更新面板。这样,更新将变得平滑且无闪烁,并且只更新更新面板内的内容。



The above code you are using will update only the content wrapped inside the update panel. The control that changes the question(next button) is located outside this update panel. So, that is causing the postback to update all the contents. You should wrap the contents to be updated asynchronously inside this update panel or you can use another update panel. That way the updation will become smooth and flicker free and only the contents inside the update panel will be updated.


这篇关于如何防止我的项目中的标题回发?我不想刷新每个问题的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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