如何在链接radiobutton列表上的按钮时重新加载Asp.net页面? [英] How to Asp.net page from reload when linking a button on radiobutton list?

查看:102
本文介绍了如何在链接radiobutton列表上的按钮时重新加载Asp.net页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我用asp.net创建了一个多项选择测验。我使用单选按钮列表来创建测验,我使用了一个标签按钮来显示结果(正确或不正确)。

我在查看结果时遇到问题,因为当我从单选按钮列表中单击任何选项时,我的页面会刷新并指向页面顶部。因此,每次我必须滚动到页面底部才能查看我的结果。

如果在这种特殊情况下停止页面指向页面顶部?



SS

Hi,

I have created a multiple choose quiz using asp.net.I have used radio button list to create quiz and I have used a label button to show the result (correct or not correct).
I am facing problem in viewing the result because when I click any option from radio button list my page get refreshed and point to the top of page. So every time I have to scroll to the bottom of the page to view my result.
How to stop page from pointing to top of the page in this particular case?

SS

推荐答案

你可以使用AJAX。你可以这样做,第一次让你的标签可见=假。当用户选择其中一个选项make label visible.Modify下面的代码lil位。(添加对ajax库的引用)



aspx页面:



You can make use of AJAX.You can do such that,first time make your label visible="false".When user selects one of the option make label visible.Modify below code lil bit.(Add the reference to ajax library)

aspx page:

<div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                    <asp:ListItem Value="a">a</asp:ListItem>
                    <asp:ListItem Value="b">b</asp:ListItem>
                    <asp:ListItem Value="c">c</asp:ListItem>
                </asp:RadioButtonList>
                <asp:Label ID="Label1" runat="server" Text="Correct answer:a" Visible="false"></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>



代码背后:




Code Behind:

protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Visible=true;
        RadioButtonList1.Visible = false;
    }


在@Page指令中设置MaintainScrollPositionOnPostback属性(MaintainScrollPositionOnPostback =true)。



当MaintainScrollPositionOnPostback属性设置为true时,用户将返回到页面的最后位置。
You set the MaintainScrollPositionOnPostback property in the @ Page directive(MaintainScrollPositionOnPostback="true").

When the MaintainScrollPositionOnPostback property is set to true, the user is instead returned to the last position on the page.


这篇关于如何在链接radiobutton列表上的按钮时重新加载Asp.net页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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