简体   繁体   English

ASPX中的按钮单击事件

[英]Button click event in aspx

I'm using Page with tabs, In 3rd tab i have search functionality But whenever i click search button page will reload and it will move to first tab. 我正在使用带有选项卡的页面,在第三个选项卡中,我具有搜索功能,但是每当我单击搜索按钮时,页面就会重新加载,并且将移至第一个选项卡。 I need tab should stay constant after button click, How can i do that? 单击按钮后我需要选项卡保持不变,我该怎么做?

<body class='default'>
<div id='jqxWidget'>
    <div id='jqxTabs'>
        <ul>
            <li style="margin-left: 30px;">UserTickets</li>
            <li>JavaServer Pages</li>
            <li>Active Server Pages</li>
            <li>Python</li>
            <li>Perl</li>
        </ul>
        <div>


        </div>
        <div>

        </div>
        <div>
        <form runat="server">


            <asp:Button ID="button" runat="server" OnClientClick="javascript:search()" Text="search" />
            <asp:Label ID="label" Text="" runat="server"></asp:Label>
            </form>
        </div>
        <div>

        </div>
        <div>

        </div>
    </div>
</div>

Thank you 谢谢

You can use update panel. 您可以使用更新面板。 In the third add update panel, below is the sample: 在第三个添加更新面板中,以下是示例:

<div id="third-tab">
 <form>
  <asp:ScriptManager runat="server" ID="ScriptMng"></asp:ScriptManager>
  <asp:Button ID="button" runat="server" Text="search" />
   <asp:UpdatePanel runat="server">
    <ContentTemplate>
     <asp:Label ID="label" Text="" runat="server"></asp:Label>
    </ContentTemplate>
    <Triggers>
     <asp:AsyncPostBackTrigger ControlId="button" />
    </Triggers>
   </asp:UpdatePanel>
 </form>
</div>

In the code behind try test below code 在后面的代码中尝试测试以下代码

protected void button_Click(object sender, EventArgs e){
 label.Text = "Searching without full reload";
}

Hope it's help 希望对你有帮助

Ajax is probably the best bet in the situation you are in. The best way to describe it is that it will just refresh content on the page that you have wrapped the AJAX around. 在您所处的情况下,Ajax可能是最好的选择。描述它的最佳方法是,它只会刷新包裹AJAX的页面上的内容。 The problem your having it that on button click it is causing the page to reload therefore going back to the 'Starter' tab. 您单击按钮时遇到的问题是导致页面重新加载,因此请回到“启动器”选项卡。

Here is a small snippet of code I have put together for you and I will explain what to do. 这是我为您整理的一小段代码,我将解释该怎么做。

  • You need to add Nugent Package to your project and add the 'Ajax Control Toolkit'. 您需要将Nugent Package添加到您的项目中,并添加“ Ajax Control Toolkit”。

  • At the top of your code you need to add this line. 您需要在代码的顶部添加此行。 (Think of it as saying 'I want to use the toolkit on this page and i will call it using AjaxControlToolkit') (以为是说“我想在此页面上使用该工具包,我将使用AjaxControlToolkit对其进行调用”)

     <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControlToolkit" %> 
  • Then you need to add the line below to your page. 然后,您需要将以下行添加到页面中。

     <AjaxControlToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></AjaxControlToolkit:ToolkitScriptManager> 
  • Then wrap the lines of code for that tab with these lines of code. 然后用这些代码行包​​装该选项卡的代码行。

     <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> </ContentTemplate> </asp:UpdatePanel> 

Make sure that you wrap all the information that tab inside the . 确保将标签中的所有信息都包装在中。

This is a very basic way of using AJAX and it can be used more advanced but this will work. 这是使用AJAX的非常基本的方法,可以使用更高级的方法,但是可以使用。

You can set Tab on Page Load conditionally. 您可以有条件地在页面加载中设置标签。 Look at this code might it will help you. 查看这段代码可能会对您有所帮助。

    var TabNum=(Your Tab Number)
    function selecttabs() {
        $('[id$="dvInvoiceTab"]').tabs("select", TabNum);
    } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM