简体   繁体   English

客户端还是服务器端?

[英]Client Side or Server side?

I am new to web development and am making an app that basically displays a listbox of documents. 我是Web开发的新手,正在开发一款基本上显示文档列表框的应用程序。 When the user clicks a document, that document (pdf) is displayed in an iFrame. 用户单击文档时,该文档(pdf)将显示在iFrame中。 All the documents are on a network share available from the server and client. 所有文档都在服务器和客户端上可用的网络共享上。 This is only going to be used internally (intranet). 这仅在内部(内部网)使用。

My questions are: 我的问题是:

Should I be changing the iFrame source at the server or client? 我应该在服务器或客户端上更改iFrame源吗? Is it even possible to do it at the client? 甚至可以在客户处进行吗?

I am trying to do it at the server. 我正在尝试在服务器上执行此操作。 I have the listbox set to auto postback, but I can't read the selectedindex because the page load occurs first (and reloads the listbox) and clears the selected item. 我已将列表框设置为自动回发,但是我无法读取selectedindex,因为页面加载首先发生(并重新加载列表框)并清除所选项目。 If I turn auto postback for the lsitbox off, the SelectedIndexchange event never fires. 如果关闭lsitbox的自动回发功能,则从不会触发SelectedIndexchange事件。

Should I be changing the iFrame source at the server or client? 我应该在服务器或客户端上更改iFrame源吗? Is it even possible to do it at the client? 甚至可以在客户处进行吗?

It's possible to do it at both, the server side and the client side. 在服务器端和客户端都可以这样做。 On the client side is done like this: 在客户端这样完成:

document.getElementById('frameID').src = "new_src.html";//or whatever

On the server side, you are probably doing it correctly but you are forgetting to add if(!IsPostBack) in Page_Load so that the data in the listbox is not rebound on every postback. 在服务器端,您可能做得正确,但是却忘记在Page_Load添加if(!IsPostBack) ,以使列表框中的数据不会在每次回发时都反弹。

Something like: 就像是:

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
       //populate list box
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM