javascript 按钮不适用于更新面板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16665648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Button is not working with Update Panel
提问by james raygan
I have placed a timer and a label for displaying countdown time in an update panel. I have placed the next button for displaying the next question outside the update panel.
我在更新面板中放置了一个计时器和一个用于显示倒计时时间的标签。我已经放置了下一个按钮,用于在更新面板外显示下一个问题。
My problem is that the button click is not working with the update panel. Without using the update panel and the timer it works well. How can I solve the problem?
我的问题是按钮单击不适用于更新面板。在不使用更新面板和计时器的情况下,它运行良好。我该如何解决问题?
I have also tried to place whole tools inside the update panel. It didn't help me.
我还尝试将整个工具放在更新面板中。它没有帮助我。
Here is my code:
这是我的代码:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="style1">
<tr>
<td class="style2">
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lblTimer" runat="server"></asp:Label>
</tr>
<tr>
<td style="margin-left: 40px" class="style3">
<asp:Label ID="lblQuestion" runat="server"></asp:Label>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<table>
<tr>
<td style="margin-left: 40px" class="style2">
<asp:RadioButtonList ID="rblOptions" runat="server">
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td style="margin-left: 40px" class="style2">
<table class="style1">
<tr>
<td class="style2">
<asp:Button ID="btnNext" runat="server" onclick="btnNext_Click" Text="Next"
Width="75px" />
</td>
<td>
<asp:Button ID="btnFinish" runat="server" onclick="btnFinish_Click"
Text="Finish" Width="75px" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblScore" runat="server">Score : </asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
<asp:UpdatePanel>
I added the following code.
我添加了以下代码。
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnNext" EventName="Click"/>
</Triggers>
Still it didn't work. Could you please help me....
仍然没有奏效。请你帮助我好吗....
The selection of radio button is automatically cleared when using update panel. Any help....?
使用更新面板时,单选按钮的选择会自动清除。任何帮助....?
Thank you....
谢谢....
采纳答案by SyntaxError
If you are using master page , then add this code in you're page load event
如果您使用的是母版页,则在您的页面加载事件中添加此代码
using AjaxControlToolkit;
?
?
ToolkitScriptManager objScriptManager = (ToolkitScriptManager)this.Master.FindControl("ScriptManager1");
objScriptManager.AsyncPostBackTimeout = 36000;
..............
……………………
回答by bastos.sergio
Your UpdatePanel is malformed. You have one extra asp:UpdatePaneltag in the markup.
您的 UpdatePanel 格式错误。标记中有一个额外的asp:UpdatePanel标记。
Use this instead:
改用这个:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="style1">
<tr>
<td class="style2">
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lblTimer" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td style="margin-left: 40px" class="style3">
<asp:Label ID="lblQuestion" runat="server"></asp:Label>
</td>
</tr>
</table>
<table>
<tr>
<td style="margin-left: 40px" class="style2">
<asp:RadioButtonList ID="rblOptions" runat="server">
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td style="margin-left: 40px" class="style2">
<table class="style1">
<tr>
<td class="style2">
<asp:Button ID="btnNext" runat="server" onclick="btnNext_Click" Text="Next" Width="75px" />
</td>
<td>
<asp:Button ID="btnFinish" runat="server" onclick="btnFinish_Click" Text="Finish" Width="75px" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblScore" runat="server">Score : </asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
<asp:UpdatePanel>
回答by bastos.sergio
Seems that are unmatched tags. Once correct and go through the layout once again. Instead of using AjaxToolkit library, run with jquery navigation plugins, you can feel more better.
似乎是无与伦比的标签。一旦正确并再次检查布局。不使用 AjaxToolkit 库,使用 jquery 导航插件运行,感觉会更好。
回答by Randhi Rupesh
You must put the Button in update pannel then it will work fine
您必须将按钮放在更新面板中,然后它才能正常工作
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="style1">
<tr>
<td class="style2">
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lblTimer" runat="server"></asp:Label>
</tr>
<tr>
<td style="margin-left: 40px" class="style3">
<asp:Label ID="lblQuestion" runat="server"></asp:Label>
</td>
</tr>
</table>
<table>
<tr>
<td style="margin-left: 40px" class="style2">
<asp:RadioButtonList ID="rblOptions" runat="server">
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td style="margin-left: 40px" class="style2">
<table class="style1">
<tr>
<td class="style2">
<asp:Button ID="btnNext" runat="server" onclick="btnNext_Click" Text="Next"
Width="75px" />
</td>
<td>
<asp:Button ID="btnFinish" runat="server" onclick="btnFinish_Click"
Text="Finish" Width="75px" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblScore" runat="server">Score : </asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
回答by Pallavi Sagar
Add
添加
<Triggers>
<asp:PostBackTrigger ControlID="btnNext" />
</Triggers>
and add Ajaxtoolkit to your project... then just give below link after <%@ Page .........%>
并将 Ajaxtoolkit 添加到您的项目中...然后在 <%@ Page .........%> 后提供以下链接
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
also add following code in your form tag.
还要在您的表单标签中添加以下代码。
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
It will solve your problem.
它会解决你的问题。
回答by ggcodes
You need to register NEXT button to update panel. for registration you need to use <asp:asyncpostbacktrigger xmlns:asp="#unknown">
inside the UpdatePanel
您需要注册 NEXT 按钮来更新面板。对于注册,您需要<asp:asyncpostbacktrigger xmlns:asp="#unknown">
在 UpdatePanel 内使用
i.e.
IE
<updatepanel>
<contenttemplate>
... body ......
</contenttemplate>
<triggers>
<asp:asyncpostbacktrigger controlid="btnNext" eventname="Click" />
</triggers>
<updatepanel></updatepanel></updatepanel>
回答by Xilmiki
If in the page there are validation error (include hidden errors es: modal dialog). Event click not work. Tray to set a different validation group to the button (es: validationGroup="xxx")
如果页面中存在验证错误(包括隐藏错误 es: modal dialog)。事件点击不起作用。托盘为按钮设置不同的验证组(es:validationGroup="xxx")
<asp:Button ID="btnFinish" validationGroup="none" runat="server" onclick="btnFinish_Click" Text="Finish" />
Hope this help.
希望这有帮助。