我有一个ASP.Net webforms应用程序,它使用Ninject 2.2.0.0
我有一个HTTPHandler,它继承自Microsoft.Web.ImageHandler类.
在其中我需要访问我创建的服务类的实例.
因为我不能从Ninject.Web.HttpHandlerBase继承我认为我只是将内核暴露为Global.asax类的属性...
protected override IKernel CreateKernel()
{
IKernel kernel = new StandardKernel(new DefaultModule());
var sms = kernel.Get<SiteMapService>();
SiteMapSvc = sms;
Kernel = kernel;
return kernel;
}
public IKernel Kernel
{
get; set;
}
Run Code Online (Sandbox Code Playgroud)
并使用kernel.Get方法获取服务..
var global = (Global) HttpContext.Current.ApplicationInstance;
var service = global.Kernel.Get<PhotoService>();
Run Code Online (Sandbox Code Playgroud)
这失败了以下......
[ArgumentNullException: Cannot be null
Parameter name: root]
Ninject.ResolutionExtensions.GetResolutionIterator(IResolutionRoot root, Type service, Func`2 constraint, IEnumerable`1 parameters, Boolean isOptional, Boolean isUnique) in c:\Projects\Ninject\ninject\src\Ninject\Syntax\ResolutionExtensions.cs:258
Ninject.ResolutionExtensions.Get(IResolutionRoot root, Type service, IParameter[] parameters) in c:\Projects\Ninject\ninject\src\Ninject\Syntax\ResolutionExtensions.cs:151
Thumb.GenerateImage(NameValueCollection parameters) in …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法将WebForm控件转换为文本.
是否有可能做到这一点:
TextBox tx = new TextBox();
tx.Text = "test";
string html = tx.HTML();
Run Code Online (Sandbox Code Playgroud)
html将在哪里:
<input type="text" value="test"/>
Run Code Online (Sandbox Code Playgroud) 这有点奇怪.请原谅下面的半伪代码.我有一个枚举值列表.比如说,就像这样:
public enum Types
{
foo = 1,
bar = 2,
baz = 3
}
Run Code Online (Sandbox Code Playgroud)
尊敬地,这将成为代码:
Types.foo
Types.bar
Types.baz
Run Code Online (Sandbox Code Playgroud)
现在我有一个下拉列表,其中包含以下列表项:
var li1 = new ListItem() { Key = "foo" Value = "Actual Representation of Foo" }
var li2 = new ListItem() { Key = "bar" Value = "Actual Representation of Bar" }
var li3 = new ListItem() { Key = "baz" Value = "Actual Representation of Baz" }
Run Code Online (Sandbox Code Playgroud)
为了完整起见:
dropDownListId.Items.Add(li1); dropDownListId.Items.Add(li2); dropDownListId.Items.Add(li3);
Run Code Online (Sandbox Code Playgroud)
希望每个人都和我在一起.我想要做的是在Autopostback上取字符串"foo"并将其转换为Types.foo - 不使用开关(因为枚举值是从数据库生成的,可能会更改).
我希望这是有道理的?知道从哪里开始?
这个主题几乎说明了一切.我有一个必须使用EstateId请求参数调用的EstateReport Web表单.我想返回一个合适的HTTP错误,这个参数我们不存在.如何返回HTTP错误400作为我的回复?
在切线上,如果不存在所需参数,我应该返回错误,我觉得更正确,还是重定向到报告的搜索页面,这更加用户友好?
我在一个简单的网页上有2个单选按钮,如果我单击其中一个,则另一个应该为false(即选中= false),但该按钮无法正常工作有人可以指出我在做的错误吗?我需要知道发生了什么事吗?
这是单选按钮:
<asp:RadioButton ID="Rb1" runat="server" Text=""/>
<asp:RadioButton ID="Rb2" runat="server" Text=""/>
Run Code Online (Sandbox Code Playgroud)
选中的已更改事件:
Protected Sub Rb1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Rb1.CheckedChanged
Rb2.Checked = False
End Sub
Protected Sub Rb2_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Rb2.CheckedChanged
Rb1.Checked = False
End Sub
Run Code Online (Sandbox Code Playgroud) 我认为这是一个"麻烦"的时刻,因为我几年没有使用圆顶WebForms开发.
我有一个转发器,其中包含一堆复选框:
<asp:Repeater EnableViewState="true" ID="IDTypesRepeater" runat="server" OnItemDataBound="IdTypesRepeaterItemDataBound">
<HeaderTemplate/>
<ItemTemplate>
<asp:CheckBox EnableViewState="true" ID="chkIdType" Text="<%# ((KeyValuePair<string,int>)Container.DataItem).Key %>" runat="server" />
<asp:HiddenField ID="idType" Value="<%# ((KeyValuePair<string,int>)Container.DataItem).Value %>" runat="server"/>
<br />
</ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
我需要获取后面代码中选中的复选框:
foreach (RepeaterItem repeaterItem in IDTypesRepeater.Items)
{
if ( ((CheckBox)repeaterItem.FindControl("chkIdType")).Checked )
{
// Do something
}
}
Run Code Online (Sandbox Code Playgroud)
但是在回发时,这段代码不起作用!我知道总是数据绑定转发器,所以我做到了这一点:
protected void Page_Load(object sender, EventArgs e)
{
IDTypesRepeater.DataSource = DocTemplateHelper.GetApplicableIDTypes().Where(type => type.Value != 0);
IDTypesRepeater.DataBind();
}
Run Code Online (Sandbox Code Playgroud)
所以这会重新填充转发器,但更新代码永远不会找到任何选中的复选框..任何想法?
我试图在我使用本教程创建的gridview中重新调整列宽,但我无法这样做.我通过谷歌搜索已经通过数十种方式,但没有他们工作.
正在创建问题的代码
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" HtmlEncode="False" />
<asp:BoundField DataField="Name" HeaderText="Name" HtmlEncode="False" />
<asp:BoundField DataField="Address" HeaderText="Address" HtmlEncode="False" />
<asp:TemplateField> // I don't want to show it in my gridview as it is just being
// for showing nested gridview
<ItemTemplate>
</td></tr>
Run Code Online (Sandbox Code Playgroud)
我试图更改列可见性,但显示/隐藏按钮不再起作用.
这就是我的gridview的样子,

我想隐藏最后一个空列或最小化它的宽度,因此它应该被隐藏并增加描述列宽度,减少ID号列宽和第一列的宽度,
我甚至尝试过CSS方式,但后来它表示宽度为0px,但宽度没有变化但是没有用ControlStyle-Width="10%".
如何授权页面仅签署具有特定角色的用户?我没有使用MVC,我不能使用[Authorize(Roles ="Admin")]属性.
案子
我有两个Web表单,还有一些代码隐藏。第一个网络表单是一个公式编写器,我在其中输入一个字符串。我想使用post方法将该字符串发送到第二个公式,并显示它。
问题
我收到一条错误消息,说无法验证MAC Viewstate:
应用程序“ /”。验证MAC Viewstate。在群集中使用电池和电池的应用程序,可确保配置的有效性,并验证算法的有效性。自动生成群集的新peutpasêtreutiliséedans。
我究竟做错了什么 ?
Webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server" action="WebForm2.aspx" method="post">
<div>
Enter your first name : <input type="text" name="FirstName"/><br />
<input type="submit" />
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Webform2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div> …Run Code Online (Sandbox Code Playgroud) 我有一个用asp webforms(.net 4.0)编写的旧项目.它使用不同的webforms服务器控件,如TextBox等.
有一个用Bootstrap编写的设计.
客户希望将"webforms上的旧项目"与"bootstrap design"结合起来.
可能吗?我在这里看到一个问题:webforms服务器控件生成自己的html代码,因此无法直接使用类似bootstrap的设计.问题是 - 如何处理这个问题,如何克服这个问题?
我没有看到一个很好的解决方案,只有重写服务器控件,如果它们不适合自举需求.是否有任何广泛使用的类似Bootstrap的Web窗体控件?
webforms ×10
asp.net ×8
c# ×3
css ×2
asp.net-4.0 ×1
controls ×1
enums ×1
gridview ×1
html ×1
httphandler ×1
ninject ×1
radio-button ×1
repeater ×1