如何在 100% 动态 AJAX ASP.NET 站点中触发 javascript
我有一个问题:
我有一个 100% 动态站点,这意味着我在起始页上只有一个更新面板。 所有内容都通过代码隐藏动态添加到default.aspx,不同的页面是Web用户控件。
当我想打开 2 个窗口(通过 ajax 控制工具包的可拖动面板)时,问题就出现了。
我想通过 javascript 定位这些面板,但定位 javascript 不运行。
请注意,我仍在网站的第一页,浏览器中没有回溯历史记录;当我在网络浏览器中“查看源代码”时,我看到登录页面的代码,这是网站打开时首先出现的代码。
我不希望任何回发导致页面历史记录,我如何执行javascript来定位我的窗口?
解决了
好吧,我通过将定位移动到服务器解决了这个问题另一方面,我创建了一个“窗口管理器”,它跟踪站点中所有打开的窗口。然后,我只需将位置添加到 Web 用户控件中的 Style 属性即可放置位置,如下所示:
protected void Page_Init(object sender, EventArgs e)
{
PartPanel.Attributes.Add("Style", Position);
}
public string Position
{
get
{
return "position:absolute;left:" + PosX "px;top:" + PosY + "px;";
}
}
I have a problem:
I have a 100% dynamic site, which means that I just have one updatepanel on the startpage.
All content is added dynamically to default.aspx via code behind, different pages are web user controls.
The problem arises when I want to open 2 windows (drag-able panels via ajax control toolkit).
I want to position these panels via javascript but the positioning javascript does not run.
Note that I'm still on the first page of the web-site, there is no back history in the browser; when I "View source" in the webbrowser I see the code for the login page, which is what comes up first when the website opens.
I don't want any postbacks causing page-history, how can I execute javascript to position my windows?
Solved it
Well I solved this issue by moving the positioning to the server side, I created a "Window Manager" which keeps track of all open windows in the site. I then just put the position by adding the position to the Style attribute in my web user control like so:
protected void Page_Init(object sender, EventArgs e)
{
PartPanel.Attributes.Add("Style", Position);
}
public string Position
{
get
{
return "position:absolute;left:" + PosX "px;top:" + PosY + "px;";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们可以有一些示例代码吗?
这种编码风格不是更容易、更适合使用通用处理程序,而不是在页面后面的代码中添加所有内容吗?我相信,这也可以消除一些管理费用。
尝试使用 Chrome 的开发人员工具或适用于 Firefox 的 Firebug 等扩展来查看源代码。这样你就可以查看和操作 DOM。您还可以使用其他有用的工具,例如 JavaScript 控制台,它将记录所有错误。
Could we have some example code?
Wouldn't this style of coding by easier and more suitable with a generic handler, rather than adding everything in the code behind a page? This would also clear some overheads, I believe.
Try using Chrome's developer tools, or an extension like Firebug for Firefox to view the source. This way you can view and manipulate the DOM. You also have other useful tools, such as a JavaScript console, which will log any errors.
或者
or
您遇到的“无历史记录”问题可以通过使用 FireFox 的 FireBug 插件来解决,该插件将向您显示实时源代码。
这比浏览器的“右键单击> >”具有很大的优势。查看源代码选项,我相信它会从服务器检索新鲜的代码。
The 'no history' issue you have can be tackled by using FireFox's FireBug plug-in, which will show you live source code.
This has a high advantage over a browsers 'Right Click > View Source' option, which I believe retrieves the code fresh from the server.