我在一个简单的ASP.NET概念验证应用程序中使用jQuery UI的可拖动和可放置库.此页面使用ASP.NET AJAX UpdatePanel进行部分页面更新.该页面允许用户将项目放入垃圾桶div中,该div将调用从数据库中删除记录的回发,然后重新绑定该项目为药物的列表(以及其他控件).所有这些元素(可拖动项和垃圾桶div)都在ASP.NET UpdatePanel中.
这是拖放初始化脚本:
function initDragging()
{
$(".person").draggable({helper:'clone'});
$("#trashcan").droppable({
accept: '.person',
tolerance: 'pointer',
hoverClass: 'trashcan-hover',
activeClass: 'trashcan-active',
drop: onTrashCanned
});
}
$(document).ready(function(){
initDragging();
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function()
{
initDragging();
});
});
function onTrashCanned(e,ui)
{
var id = $('input[id$=hidID]', ui.draggable).val();
if (id != undefined)
{
$('#hidTrashcanID').val(id);
__doPostBack('btnTrashcan','');
}
}
Run Code Online (Sandbox Code Playgroud)
当页面回发,部分更新UpdatePanel的内容时,我重新绑定了draggables和droppables.当我用光标抓住一个draggable时,我得到一个"htmlfile:Unspecified error".例外.我可以通过替换elem.offsetParent对我写的这个函数的调用来解决jQuery库中的这个问题:
function IESafeOffsetParent(elem)
{
try
{
return elem.offsetParent;
}
catch(e)
{
return document.body;
}
}
Run Code Online (Sandbox Code Playgroud)
我还必须避免调用elem.getBoundingClientRect(),因为它会抛出相同的错误.对于那些感兴趣的人,我只需要jQuery.fn.offset在Dimensions插件中的函数中进行这些更改.
我的问题是:
更新:
@some它不公开,但我会看到SO是否允许我将相关代码发布到这个答案中.只需创建一个ASP.NET Web应用程序(将其命名为 …
触发更新时更新的内容是什么?什么去服务器?什么回来了?
我的印象是只有面板的内容被传输到服务器并返回(没有触摸面板外的页面中的任何内容),但我遇到了奇怪的结果,可能是因为我真的不明白它是如何工作的究竟.
有人可以提供一个简单的解释,它是如何工作的?
我有一个最初绑定到sqldatasource控件的asp.net gridview,但是当用户按下外部按钮时,它会获取数据表而不是SQLdatasource控件的内容.因此,我必须在gridview的PageIndexChanging事件中编写代码以允许分页.我的代码如下:
Protected Sub gvEvents_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvEvents.PageIndexChanging
gvEvents.PageIndex = e.NewPageIndex
gvEvents.DataBind()
Run Code Online (Sandbox Code Playgroud)
这非常有效,直到我添加了一个AJAX更新面板,因此每次分页时整个页面都不会回发,并且分页停止工作.我调试它并发现它实际上正在调用PageIndexChanging事件,但什么也没发生.
我搜索了网络,发现一些人有同样的问题,但他们的解决方案对我不起作用.这个网站上有一个问题通过以下方式解决:
在PageIndexchanging事件中,将数据绑定到网格,确保再次从数据库中提取数据
我不知道这意味着什么; 如上所示,我的数据受到约束.我将"enable paging"设置为true,将EnableSortingAndPagingCallbacks设置为false.
如果有人可以帮助我,我真的很感激.我在下面的updatepanel中包含了我的标记.非常感谢!
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ibtnSearch" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="gvEvents" runat="server" DataKeyNames = "intID"
AutoGenerateColumns="False" AllowPaging="True" GridLines="None" CellPadding="10"
ForeColor="#333333" PageSize="6" DataSourceID="defaultDS" >
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Date">
<ItemTemplate>
<!-- put code block inside label? To set the formatter to include year if
it's next year? -->
<asp:Label ID="Label1" runat="server"
Text = …Run Code Online (Sandbox Code Playgroud) 嗨我需要在udate面板异步回发后拦截服务器回调并确定哪个面板发起了请求.代码非常简单:
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(InterceptUpdateCallback);
function InterceptUpdateCallback(sender, args)
{
var updatedPanels = args.get_panelsUpdated();
for (idx = 0; idx < updatedPanels.length; idx++) {
if (updatedPanels[idx].id == "myUpdatePanel") {
StartSmth();
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
当UpdatePanel不在另一个UpdatePanel中时,它可以工作.但是当它在另一个UpdatePanel内时,updatedPanels [idx] .id具有父Updatepanel id.那么我怎样才能获得启动请求的UpdatePanel的id(内部UpdatePanel)?感谢名单
这是我正在处理的webapp中遇到的一个问题.
因此,我没有用不相关的代码混淆问题,而是在一个孤立的,简化的webapp中重新创建了问题,只展示了这个问题.
希望这有助于找到解决方案.
我有一个Web用户控件,其内容如下:
<% if (ShowAlertScript)
{ %>
<script type="text/javascript">
function AlertMe()
{
alert('Hello World!');
}
</script>
<% } %>
<input type="button" onclick="AlertMe()" value="Say Hello" />
Run Code Online (Sandbox Code Playgroud)
它的代码隐藏只不过是布尔定义ShowAlertScript.
这表示我在大型webapp中具有的控件有两种模式:输入模式和显示模式.在输入模式下,它有一个大的javascript块,只有用处; 它做了一些很酷的东西来帮助用户输入信息.
这种控制在大局中的布局方式如下:
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:MultiView ActiveViewIndex="0" runat="server" ID="mvw">
<asp:View runat="server">
<asp:Button runat="server" ID="btnSwitch"
OnClick="btnSwitch_Click" Text="Switch" />
</asp:View>
<asp:View runat="server">
<uc:MyInputControl runat="server" ID="micInput" ShowAlertScript="true" />
</asp:View>
</asp:MultiView>
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
单击时btnSwitch,它只需使用用户控件切换到第二个视图.请注意我ShowAlertScript已经初始化了true.
可能的输出是,因为我在用户控件中"显示警报脚本",所以AlertMe()当您单击input-button …
所以问题如下:
我有自己的用户控制权.其中包含脚本标记中的一些javascript文件
<script type="text/javascript" src="../somefile.js" ></script>
Run Code Online (Sandbox Code Playgroud)
或者直接在ascx页面上的一些javascript代码.如果我把这个控件放在aspx标记的某个地方,一切都有效.但是如果我将这个控件动态地添加到页面上的一些UpdatePanel占位符(这是我不能改变的逻辑),控件呈现自己然后我得到js错误消息,这表示放在somefile.js中的函数是未定义/为空.为什么会这样?无论如何强制js包括在这种情况下.
抱歉没有足够具体但代码量巨大,我无法提供相同错误的简化示例.
包含脚本,但不知何故未定义函数.我是js的新手,所以是否可能只包含脚本但未执行,因此函数未声明???
有趣的是,如果在某些页面上我的自定义控件是在aspx中声明的.动态添加更多实例不会造成任何问题.
我通过调用这样的方法来刷新UpdatePanel和Javscript:
reloadDropDown = function (newValue)
{
__doPostBack("DropDown1", "");
selectNewValueInDropDown(newValue);
}
Run Code Online (Sandbox Code Playgroud)
在我的UpdatePanel里面是一个<select>框,我需要<option>用newValue选择一个框.我的问题是我的selectNewValueInDropDown方法在__doPostBack完成之前被调用.有没有办法在调用我的selectNewValueInDropDown方法之前"等待"回发?
看看这个标记:
<asp:UpdatePanel ID="Panel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="cboBox1" ClientIDMode="Static" AutoPostBack="true" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="cboBox2" runat="server" />
<asp:UpdateProgress ID="UpdateProgress1" style="display: inline" AssociatedUpdatePanelID="Panel1" DynamicLayout="false" DisplayAfter="0" runat="server">
<ProgressTemplate>
<img src='<%= ResolveClientUrl("~/Images/indicator.gif")%>' border="0" alt="" />
</ProgressTemplate>
</asp:UpdateProgress>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cboBox1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
UpdateProgress控件最初工作,但是当我们将ClientMode ="Static"添加到cboBox1时,它就崩溃了.将其还原为AutoID不是一个选项,因此我需要找到允许UpdateProgress面板与ClientIDMode ="Static"一起使用的解决方案.
另外,有人可以在标签列表中添加"clientidmode"吗?
我有一个用户控件放在更新面板中,就像这样.
<asp:UpdatePanel ID="testupdatepnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<uc1:TestControl ID="ctlTest" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
现在我在这个用户控件里面放了一个按钮说Click.我想在按钮点击上回发整个页面.我试着像这样添加一个回发触发器
<Triggers>
<asp:PostBackTrigger ControlID="clickButton" />
</Triggers>
Run Code Online (Sandbox Code Playgroud)
由于按钮位于用户控件内部,因此在运行时出现错误.
有没有办法为这个按钮做回发.
我<base href="http://localhost:80/">在我的主页中使用基本网址,
现在,当我在更新面板中的dropdownlist内容页面(位于localhost:80/directory1/directory2)上使用控件时,selectedindexchanged事件无法正常工作.
我试图搞清楚,但在firefox控制台的网络选项卡中,我发现请求正在寻找url仅在基础上的内容页面localhost:80/contenpage.aspx而不是localhost:80/directory1/directory2/contenpage.aspx并且给出错误
无法找到该资源.
asp.net ×10
updatepanel ×10
javascript ×3
asp.net-ajax ×2
c# ×2
postback ×2
ajax ×1
gridview ×1
jquery ×1
paging ×1
static ×1
vb.net ×1
webforms ×1