我想知道你将如何展示,然后隐藏有关页面状态的div。
例如,我有一个上传按钮,一旦文件上传,我希望页面切换到下一个方法,这将显示另一个“页面”并从所需内容中提取相关信息。
我当前的“viewstate”代码是
<script runat="server">
//This template is being built to allow the viewstates to be displayed and allow them to be hidden
//or shown at the same time. The buttons are being added so we can test whether they will
//be hidden on page use
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string viewStateDisplay = "ViewState 2 is now being displayed";
if (ViewState["PageState"] == null)
{
ViewState["PageState"] = viewStateDisplay;
}
}
}
//button that shows the label string
protected void btnClick_Click(object sender, EventArgs e)
{
lblString.Text = ViewState["PageState"].ToString();
lblString.Visible = true;
}
//button that hides the div, changing "lblstring" or adding more should be able to hide
//or show whatever methods / objects we want
private void Close(object sender, EventArgs e)
{
lblString.Visible = !lblString.Visible;
lblString.Visible = false;
}
</script>
<!-- The following section will include all the html and forms etc !-->
<div>
ViewState Data: <b><asp:Label ID="lblString" runat="server"/></b>
<asp:Button ID="btnClick" runat="server" Text="Get ViewState Data" OnClick="btnClick_Click"/>
<asp:Button ID="Closeform" runat="server" Text ="Hide PageState" OnClick="Close" />
</div>
我有一种感觉,我必须将两个步骤设置为false,然后根据我希望它出现的位置为每个方法设置一个数字。
如
If request ("thing") then methodName
end if
if request ("second thing") then viewstate new method
if nothing viewstate 1
step1.visible = false
step2.visible = false
但我不知道如何将其转换为可行的C#代码,使用我的原始代码并在此实现我自己的方法,感谢帮助,谢谢。
答案 0 :(得分:0)
就我的问题而言,您希望在文件上传完成后切换页面,然后为此,您可以按照以下方法之一进行操作:
使用隐藏按钮:
<asp:Button ID="HdnButtonID" runat="server" Style="visibility: hidden" OnClick="moveToNextPage" />
点击你的上传按钮,调用javascript函数并点击按钮事件:
function onClickofUploadButton()
{
FireEvent(HdnButtonID);
}
这将触发您的服务器端代码,您可以在其中保存Session中的数据并重定向到新页面。