开发者

How to fire javascript in 100% dynamic AJAX ASP.NET site

开发者 https://www.devze.com 2023-03-12 16:29 出处:网络
I have a problem: I have a 100% dynamic site, which means that I just have one updatepanel on the startpage.

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;";
        }
    开发者_开发知识库}


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.


 public void setPage(mshtml.HTMLWindow2Class JSFile) {
        window = JSFile;
}
public void scriptPrint(){
        window.execScript("report_back('Printing complete!')", "JScript");
}

or

Page.RegisterStartupScript("myScript", "<script language=JavaScript>hi('" + whatever + "');</script>");


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消