我正在使用“更新面板”,我的回答中包含一些类似波纹管的JavaScript。成功响应后,我需要评估,加载(使用外部脚本)
例如:我的HTML回应
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript">
alert('asd');
</script>
<div>test</div>
<div>blah blah blah</div>
Run Code Online (Sandbox Code Playgroud) 我接到了一个巨大的 Webforms 项目,我试图理解它,但我遇到了一个问题,即更新面板复制了很多内容。面板的 aspx 代码很大,有数百行,但它基本上看起来像这个简单的例子,只有更多asp:TextBox和asp:ListBox.
<asp:UpdatePanel runat="server" ChildrenAsTriggers="true" RenderMode="Block" UpdateMode="Conditional">
<ContentTemplate>
<div><table><tbody><tr><td>
<label>Search</label><asp:TextBox ID="Search" runat="server" />
<asp:LinkButton runat="server" OnClick="find_Click" >Find</asp:LinkButton>
</td></tr></tbody></table></div>
<div id="a"><table><tbody><tr><td>
<label>Result</label><asp:TextBox ID="Result" runat="server" />
</td></tr></tbody></table></div>
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
和这样的代码。
public void find_Click(Object sender, EventArgs e)
{
Result.Text = "oranges";
}
Run Code Online (Sandbox Code Playgroud)
当您单击 LinkButton 时,我希望在结果中看到该<div id="a">部分,但在 TextBox 中看到文本“oranges”。你实际得到的是<div id="a">“橙子”,然后是<div id="a">带有空文本框的原始文本。最糟糕的一点是,它没有做,在这个简单的例子,甚至也不是在一个页面中,我创建了所有原始asp:TextBox和asp:ListBox,但以虚拟数据填充。任何人都可以指出我解决这个问题的任何好方法吗?
我点击链接时使用fancybox显示div的内容.这可以使用下面的代码:
<a id="popupTrigger" href="#popup">popup trigger</a>
<div style="display:none">
<div id="popup">
<asp:UpdatePanel ID="HerkomstCodeUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
This content displays inside fancybox.
<asp:TextBox ID="CurrentTimeTextBox" runat="server"></asp:TextBox>
<asp:Button ID="RefreshContentButton" runat="server"></asp:Button>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和JScript:
$(document).ready(function () {
$("#popupTrigger").fancybox({
autoDimensions: false,
height: 250,
transitionIn: 'elastic',
transitionOut: 'elastic',
width: 400
});
});
Run Code Online (Sandbox Code Playgroud)
现在我期待它会做的是,当你点击按钮(显示在fancybox中)时,它会更新文本框并执行我在代码隐藏中定义的任何内容.不幸的是,单击按钮时没有任何反应.
我试图触发一个__doPostback自己传递updatepanel的ClientID和/或按钮本身.但我似乎无法触发代码隐藏中的事件.
问题是,如果我删除fancybox,updatepanel按预期工作.所以我猜我是否可以在创建fancybox之前以某种方式找出按钮背后的事件处理程序逻辑,我可能能够在附加fancybox后重新创建eventhandler逻辑?我在任何地方都找不到它......
我正在使用ASP.Net WebForms 3.5和JQuery 1.4.1
更新
我通过使用下面的代码覆盖按钮上的客户端点击事件来触发codebehind button_click事件.关键是使用按钮的名称作为__doPostBack事件的发送者对象.剩下的唯一问题是所有其他值都不再发布.如果我在文本框中输入任何内容,请单击按钮,我的代码隐藏不再知道文本框中的内容.
$("#popupTrigger").fancybox({
//.... other options,
onComplete: function () {
$("#RefreshContentButton").click(function () {
__doPostBack($(this).attr('name'), '');
});
}
});
Run Code Online (Sandbox Code Playgroud) 我正在使用 anUpdatePanel来交换ActiveViewa 的MultiView。
在 IE6、7 和 8 以及 Chrome 7 中,当 UpdatePanel 返回时,我收到 JavaScript 错误。在 Firefox 3.6.1 中,没有报告错误(在错误控制台或 Firebug 中)。
错误位于 ScriptResource.axd 的第 3621 行
function Sys$_ScriptLoader$_loadScriptsInternal() {
var session = this._currentSession;
if (session.scriptsToLoad && session.scriptsToLoad.length > 0) {
var nextScript = Array.dequeue(session.scriptsToLoad);
var scriptElement = this._createScriptElement(nextScript);
if (scriptElement.text && Sys.Browser.agent === Sys.Browser.Safari) {
scriptElement.innerHTML = scriptElement.text;
delete scriptElement.text;
}
if (typeof(nextScript.src) === "string") {
this._currentTask = new Sys._ScriptLoaderTask(scriptElement, this._scriptLoadedDelegate);
this._currentTask.execute();
}
else { …Run Code Online (Sandbox Code Playgroud) 我想在单击HyperLink时触发更新面板更改但是我收到一条错误说:
Control with ID 'X' being registered through RegisterAsyncPostBackControl or RegisterPostBackControl must implement either INamingContainer, IPostBackDataHandler, or IPostBackEventHandler.
Run Code Online (Sandbox Code Playgroud)
如果我使用ASP按钮,那么一切正常
我的代码:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateButton2" eventname="Click" />
</Triggers>
<ContentTemplate>
<asp:Repeater ID="rptDossiers" runat="server">
<ItemTemplate>
...
</ItemTemplate>
</asp:Repeater>
<asp:HyperLink NavigateUrl="#" runat="server" id="UpdateButton2" onclick="tousLesDossiers_Click">
Tous les Dossiers
</asp:HyperLink>
<%--<asp:Button runat="server" id="UpdateButton2" onclick="tousLesDossiers_Click" text="Update" />--%>
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
有什么建议?
谢谢
进行更改后,我无法刷新 Updatepanel 中的 Gridview。有人可以帮忙吗?我在 GridView 中使用 rowCommand 删除行。我正在使用 ToolkitScriptManager 控件和 UpdatePanel。
<asp:UpdatePanel runat="server" ID="upt1">
<ContentTemplate>
<asp:GridView ID="gwSubG1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" Width="600px" OnSelectedIndexChanged="gwSubG1_SelectedIndexChanged" DataKeyNames="One_Grop_Id" OnRowCommand="gwSubG1_RowCommand" OnRowDeleting="gwSubG1_RowDeleting">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Grop_Name" HeaderText="Group One" ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="HeaderCenter">
<HeaderStyle CssClass="HeaderCenter" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="ORG_Grp_Nam" HeaderText="Main Group" ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="HeaderCenter">
<HeaderStyle CssClass="HeaderCenter" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnDelete" ImageUrl="~/Theme/Icon/info.png" CausesValidation="false" runat="server" CommandArgument='<%# Eval("One_Grop_Id") %>' CommandName="Delete" AlternateText="Delete" OnClientClick="return confirm('are you sure?');" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel> …Run Code Online (Sandbox Code Playgroud) 我有一个小的 C# 代码,用于在 15 秒后刷新 Web 表单页面 (form.aspx),如下所示:
lblMessage.Text = "<b><h2>Thank you!</h2></b></br>We will be right with you.<br><br><br>(This page will be refreshed automatically after 15 seconds)";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Success!", "setInterval(function(){location.href='/form.aspx';},15000);", true);
Run Code Online (Sandbox Code Playgroud)
现在页面将在 15 秒后刷新。如何让计时器每秒倒计时?即,15 => 14 => 13 => ... 1 然后刷新,这样对用户来说会更好,他们会知道页面发生了什么...
我在更新面板外有一个按钮,可以很好地控制更新面板。当点击事件被触发时,我还想要另一个按钮来更新这个相同的更新面板。我怎样才能做到这一点?
我在更新面板中有一个标签和按钮,当我尝试从按钮单击的标签上获取值时,我从标签获取值,但是当我尝试将值设置为标签时,它不会发生,我检查JavaScript错误,但没有任何,有没有人有任何猜测可能是什么原因.我正在使用dotnetnuke,这是我的代码
<asp:UpdatePanel ID="updSection6" runat="server"><ContentTemplate>
<asp:Label ID="lbl" runat="server" />
<asp:ImageButton ImageUrl="/images/edit.gif" ID="btnEditSectionStory6" runat="server" OnClick="Clicked" />
</ContentTemplate></asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
这是代码
protected void Clicked(object sender, EventArgs e)
{
lbl.Text="Welcome";
}
Run Code Online (Sandbox Code Playgroud) 我有J Query事件被分配document.ready,我的页面也有update panel.当partial post back在页面中发生了,我的损失J query events.
是有之间的冲突document.ready和update panel?我怎么解决这个问题?
updatepanel ×10
asp.net ×9
ajax ×2
c# ×2
jquery ×2
webforms ×2
asp.net-3.5 ×1
asp.net-ajax ×1
button ×1
fancybox ×1
gridview ×1
html ×1
javascript ×1
label ×1
rowcommand ×1
timer ×1