在网站上放置一个文本框,一个复选框和一个按钮.将textbox的"EnableViewState"属性设置为false,将复选框设置为false.将内容写入文本框并选中复选框.单击按钮.
为什么仍然会写入文本框并在响应后选中复选框?
示例 1:
<asp:Panel Visible="false" runat="server">
<asp:TextBox ID="textbox" runat="server" />
</asp:Panel>
Run Code Online (Sandbox Code Playgroud)
在这里,textbox.Visible返回false代码(即使TextBox.Visible没有明确设置;它似乎从其不可见的父级“继承”了该属性)。
示例 2:
<asp:DataGrid ID="grid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<asp:TextBox ID="textbox" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
...
</asp:DataGrid>
Run Code Online (Sandbox Code Playgroud)
在这里,((TextBox)grid.Items[0].FindControl("textbox")).Visible返回true(假设 DataGrid 至少有一行)。
问题:这是设计的不一致行为吗?在这两种情况下,都不会呈现 TextBox,因为某些父元素不可见。
(当然,在第二种情况下,文本框位于模板内,但我不是在模板定义中查询抽象文本框,而是在第 0 行查询特定的具体文本框。)
背景: TextBox 是一个智能控件:它仅在不可见时才将其 Text 属性保存在 ViewState 中。这是有道理的:如果 TextBox 可见,它将呈现为 HTML<input>控件,并且其当前Text值在回发时提交 - 无需通过 ViewState 再次提交。当然,如果 TextBox 不可见,则不会呈现它,因此,对Text属性所做的任何更改都将丢失。
现在,示例 2 给我们带来了一些麻烦。textbox认为它正在被渲染(根据 IL spy,它在 …
我有一个稳定的错误,每次击中F5时都会重现:

有两个网格(主 - 细节),当主网格上发生聚焦行更改事件时,我的客户端代码引发的回调实际上发生了错误.像这样的东西:
this.mainGrid.ClientSideEvents.FocusedRowChanged = string.Format(@"
function(s, e)
{{
if (typeof({0}) != 'undefined')
{0}.PerformCallback(s.GetFocusedRowIndex());
}}",
this.detailsGrid.ClientInstanceName);
Run Code Online (Sandbox Code Playgroud)
这个bug只能在mozilla firefox中重现!(是的,IE没有问题,这有点奇怪=))
非常重要的是:只有当事件验证开启时,bug才会重现,即:
... EnableEventValidation="false" %> // no error in this case
Run Code Online (Sandbox Code Playgroud)
我建议原因是在必要的字段加载之前回调被触发(因为我得到它,事件验证使用一些隐藏的字段),所以我检查了使用setTimeout:
this.mainGrid.ClientSideEvents.FocusedRowChanged = string.Format(@"
function(s, e)
{{
window.setTimeout(function () {{
if (typeof({0}) != 'undefined') {0}.PerformCallback(s.GetFocusedRowIndex());
}}, 2000);
}}",
this.detailsGrid.ClientInstanceName);
Run Code Online (Sandbox Code Playgroud)
但是tat并没有帮助.2秒后,回叫开始,我收到错误.它仅在刷新时发生 - 第一次加载页面时不会引发错误.禁用网格的行缓存也没有帮助.需要帮助!=))
编辑:这是StackTrace
at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
at System.Web.UI.ClientScriptManager.EnsureEventValidationFieldLoaded()
at System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument)
at System.Web.UI.Control.ValidateEvent(String …Run Code Online (Sandbox Code Playgroud) 在我的asp.net c#页面上,我有两个带有ajax CalendarExtenders的文本框(开始和结束日期).用户选择开始日期然后选择结束日期.在选择结束日期时,我绑定我的网格,如下所示;
protected void calEndDate_TextChanged(object sender, EventArgs e)
{
BindGrid();
}
Run Code Online (Sandbox Code Playgroud)
在网格中,我有一个带有以下代码的命令按钮
protected void gvAllRoomStatus_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Manage")
{
GridViewRow row = gvAllRoomStatus.Rows[Convert.ToInt16(e.CommandArgument)];
int BookingID = Convert.ToInt32(row.Cells[1].Text);
DataClassesDataContext context = new DataClassesDataContext();
Session["BookingID"] = BookingID;
Response.Redirect("CheckIn.aspx");
}
}
Run Code Online (Sandbox Code Playgroud)
当用户转到该页面并单击后退按钮时,所有选定的日期和gridview数据都会消失.任何想法为什么观点正在消失?
我正在使用Burp Suite在站点上进行一些安全测试,我注意到当它检测到 ViewState 时,它会自动告诉您它是否启用了 MAC。
我很好奇是否有人知道一种编程方式来确定是否启用了 MAC,如果您正在爬行一个站点而没有实际尝试修改 ViewState,提交它并查看是否有任何问题?
据我所知,Burp Suite 只是通过查看请求(而不是修改/提交)来执行此操作。
我有一些查询数据库并将结果放入 gridview 的函数。它还设置了一个包含查询结果的 ViewState 变量。当我回发时,我有一个加载函数,可以从最后的结果加载 gridview(如果有的话)。
我遇到的问题是我收到一个错误,基本上说 viewstate 对象需要序列化。从我所拥有的,我不知道如何做到这一点。
错误:Sys.WebForms.PageRequestManagerServerErrorException:错误序列化值 'System.Collections.Generic.List
1[<>f__AnonymousType172[System.Int32,System.String]]' 类型为 'System.Collections.Generic.List1[[<>f__AnonymousType172[[System.Int32, mscorlib,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089],[System.String,mscorlib,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]],App_Web_rjb502Culture=Version PublicKeyToken=null]].'
到目前为止我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Runtime.Serialization;
public partial class PlayersManagement : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadData();
}
}
public void LoadData()
{
if (ViewState["CurrentGridView"] != null || ViewState["CurrentGridView"] == "")
{
GridViewPlayers.DataSource = ViewState["CurrentGridView"];
GridViewPlayers.DataBind();
}
else
{
DBModel.DBEntities context = new …Run Code Online (Sandbox Code Playgroud) 我正在使用 asp.net webform 网站,该网站使用 4.5 框架和 vunrability 扫描仪将 viewstate 显示为Unencrypted __VIEWSTATE parameter
即使我使用机器密钥它仍然标记它
<machineKey validationKey="xxxxxxxxxxxx" decryptionKey="xxxxxxxxxxxx" validation="SHA1" decryption="AES" />
Run Code Online (Sandbox Code Playgroud)
这就是在 asp.net webform 4.5 中对 viewstate 进行加密的方式吗
回发:如何在我的代码隐藏文件中访问ASP.NET控件,这些文件是以编程方式添加的?
我将一个CheckBox控件添加到占位符控件:
PlaceHolder.Controls.Add(new CheckBox { ID = "findme" });
Run Code Online (Sandbox Code Playgroud)
Request.Form.AllKeys除了我以编程方式添加的控件外,ASPX文件中添加的控件显示正常.我究竟做错了什么?
在控件上启用ViewState没有用.如果只是那么简单:)
我有一个非常简单的网页,ViewState禁用所有地方:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" EnableViewState="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" EnableViewState="false"></asp:TextBox>
<asp:DropDownList runat="server" id="mylist" EnableViewState="false">
<asp:ListItem>my item 1</asp:ListItem>
<asp:ListItem>my item 2</asp:ListItem>
<asp:ListItem>my item 3</asp:ListItem>
<asp:ListItem>my item 4</asp:ListItem>
<asp:ListItem>my item 5</asp:ListItem>
<asp:ListItem>my item 6</asp:ListItem>
</asp:DropDownList>
<asp:Button runat="server" Text="click me"/>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
代码背后
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("Dropdown list value is " + mylist.SelectedValue); …Run Code Online (Sandbox Code Playgroud) 我有一个asp.net页面,其中我使用枚举(在app_code中的类文件中定义了属性)
现在我的问题是,无论何时页面获得回发,属性中的枚举值都会重置为第一个
我甚至尝试将属性设置为静态,但仍然没有帮助.
下边是我的枚举和财产声明:
private static UrlType _type;
public static UrlType UrlPattern
{
get
{
HttpContext.Current.Response.Write("GET: " +_type + "<br>");
return _type;
}
set
{
_type = value;
HttpContext.Current.Response.Write("SET : " +_type + "<br>");
}
}
public int VanityId { get; set; }
public enum UrlType
{
ArticleOnly,
ArticleCategoryCombination,
Normal,
TechForum
}
Run Code Online (Sandbox Code Playgroud)
这就是我所说的:
public void BindRewrite()
{
GrdRewrite.DataSource = objVanity.GetAllRewriteVanities(Vanity.UrlPattern);
GrdRewrite.DataBind();
if (Vanity.UrlPattern == Vanity.UrlType.ArticleCategoryCombination)
{
GrdRewrite.Columns[2].Visible = false;
GrdRewrite.Columns[3].Visible = GrdRewrite.Columns[5].Visible = GrdRewrite.Columns[6].Visible = true;
}
else if …Run Code Online (Sandbox Code Playgroud)