Tag: asp.net

MVC路由不适用于虚拟目录上的非默认/根操作控制器

我在IIS上使用默认的“ASP.NET MVC 2 Web应用程序”(我没有管理员访问权限),而我可以导航到 “服务器/ ITEC” 如果服务器没有返回错误,我无法导航到“server / ITEC / About” – 404错误。 我也使用RouteDebugger进行测试 – 当我使用默认的“server / ITEC”时它匹配(也就是默认的home / index控制器动作)但是当我手动输入“server / ITEC / About”时我甚至看不到RouteDebugger页面。 另外值得注意的是,当我在“server / Itec / About”中放置一个“index.html”文件时,它返回结果,这使我相信目录配置为在处理请求时使用文件系统而不是MVC路由 – 这是一个安全的假设吗? 如何更新我的Global.asax文件以便我可以返回非默认控制器/操作? 或者这是一个服务器问题,我该如何解决这个问题? 谢谢! using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace mikeProg { // Note: For instructions on enabling […]

设置ASP.NET Button属性客户端和读取属性值服务器端

在使用javascript更改属性值后,如何检索Button自定义属性? 例: Asp文件 var btn1 = ‘#’; var btn2 = ‘#’; $(btn1).click(function(e) { e.preventDefault(); $(btn2).attr(“actIndex”, “2”); }); CodeBehind文件 protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) Button2.Attributes.Add(“actIndex”,”1″); } protected void Button2_Click(object sender, EventArgs e) { Button btn = (Button)sender; // this should be 2 if button1 has been clicked string actIndex = btn.Attributes[“actIndex”]; } 如果我单击Button1然后单击Button2 […]

如何使用htmlagilitypack刮取xml文件

我需要从http://feeds.feedburner.com/Torrentfreak中抓取一个xml文件,以获取其链接和描述。 我用过这段代码: var webGet = new HtmlWeb(); var document = webGet.Load(“http://feeds.feedburner.com/TechCrunch”); var TechCrunch = from info in document.DocumentNode.SelectNodes(“//channel”) from link in info.SelectNodes(“//guid[@isPermaLink=’false’]”) from content in info.SelectNodes(“//description”) select new { LinkURL = info.InnerText, Content = content.InnerText, }; lvLinks.DataSource = TechCrunch; lvLinks.DataBind(); 我已经在列表视图控件中使用它来在asp.net页面上显示。 运用 – 但它显示错误 值不能为空。 参数名称:source 有什么问题 ? 是否可以使用HtmlAgilityPack刮取(获取)xml节点数据? 请建议谢谢

使用C#不能在DropDownList中选择多个项目

当我尝试从下拉框“不能在DropDownList中选择多个项目”中选择项目时,我收到此错误。 有人可以帮助我,我不知道为什么我得到这个。 这是我的代码: private void Bind_GridView() { this.BindGroupNameList(DropDownList1); } private void GetGroupNameList(DropDownList DropDownList1) { String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings[“MyConnectionString”].ConnectionString; SqlConnection con2 = new SqlConnection(strConnString); SqlDataAdapter sda = new SqlDataAdapter(); SqlCommand cmd1 = new SqlCommand(“select distinct Name” + ” from MyTable”); cmd1.Connection = con2; con2.Open(); DropDownList1.DataSource = cmd1.ExecuteReader(); DropDownList1.DataTextField = “Name”; DropDownList1.DataValueField = “Name”; DropDownList1.DataBind(); con2.Close(); DropDownList1.Items.FindByValue(ViewState[“MyFilter”].ToString()) […]

在GridView编辑模板中更改控件的值

我有一个GridView,我需要能够以编程方式更改编辑模板中TextBox的值。 当我在onRowDataBound期间尝试访问它时,我得到了这个: exception详细信息:System.NullReferenceException:未将对象引用设置为对象的实例。 我想在onRowDataBound方法中,编辑模板控件是不可访问的。 但是,当我尝试在onRowEditing方法中编辑TextBox的值时,GridViewEditEventArgs对象没有.Row选项,因此看起来您无法访问onRowEditing方法中编辑模板中的控件。 有关如何以编程方式更改GridView编辑模板中TextBox值的任何想法? ASP.NET WebForms,.NET 4.0,C# ==== 编辑#1:这就是我现在拥有的。 在RowEditing中,txtMiles对象最终为null。 <asp:Label ID="lblFreqMiles" runat="server" Text='’> <asp:TextBox ID="txtFreqMiles" runat="server" Text='’ Width=”50px”> protected void gvMaint_RowEditing(object sender, GridViewEditEventArgs e) { //format Miles Frequency column GridViewRow row = grvMaint.Rows[e.NewEditIndex]; TextBox txtMiles = (TextBox)row.FindControl(“txtFreqMiles”); if (txtMiles.Text == “999999”) { //do stuff } grvMaint.EditIndex = e.NewEditIndex; populateMaintGrid(); }

使用CSS更改ASP.NET中dropdownlist所选项目的背景颜色

我想在下拉列表,列表框和文本框中更改所选项目的背景颜色。 这可能与CSS有关吗? 谢谢 UPDATE 刚试过这个CSS: ::-moz-selection { background-color:#8CCA1E; color:Black; } 适用于所选文本,但不适用于下拉列表或列表框中的hover颜色或选定项目颜色。

要调用此方法,“Membership.Provider”属性必须是“ExtendedMembershipProvider”的实例

我遇到了这个错误,我无法弄明白。 我通过Chrome中的PostMan将数据发布到我的控制器,达到CreateUserAndAccount方法,并收到此错误: To call this method, the “Membership.Provider” property must be an instance of “ExtendedMembershipProvider”. 这是我的控制器: [System.Web.Http.Authorize] [InitializeSimpleMembership] public class AccountController : ApiController { // POST: /api/register [System.Web.Http.HttpPost] [System.Web.Http.AllowAnonymous] [ValidateAntiForgeryToken] //public HttpResponseMessage Register(RegisterModel model, string returnUrl) public HttpResponseMessage Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); // […]

如何从ASP.NET读取条形码?

我不确定,这是否可能? 我想从ASP.NET网站扫描条形码。 有人知道怎么做吗?

调用堆栈仅包含外部代码

当我点击另一个时,我希望它变得可见。 我是用jQuery做的,但我并不坚强。 我写了脚本: $(document).ready(function () { $(‘.visiblePanel’).on(‘click’, function () { $(‘.invisiblePanel’).toggle(); }); }); 我通过С#做的布局: Panel visiblePanel = new Panel(); visiblePanel.Style.Add(“background-color”, “red”); visiblePanel.CssClass = “visiblePanel”; Panel invisiblePanel = new Panel(); invisiblePanel.CssClass = “invisiblePanel”; 当然,它没有用。 但也是一个错误: 没有脚本一切都很好。 我试图禁用Just My Code并得到它: 真的,我用Google搜索了该怎么做,但没有成功。 你可以帮帮我吗? PS在jsfiddle.net我的脚本工作。 http://jsfiddle.net/ZMxg8/ PPS:问题不在脚本中! VS发生了什么? 什么意思“调用堆栈只包含外部代码”???

如何在ASP.NET中没有任何回发的情况下上传图像文件

我使用和控件上传文件,但我想在没有回发的情况下执行此操作。 在按钮上单击我执行以下代码。 protected void btnUpload_Click(object sender, EventArgs e) { string strFileName = Path.GetFileName(FileUpload1.FileName); //fileupload1 is the <asp:fileupload ID FileUpload1.SaveAs(Server.MapPath("~/UploadFile/" + strFileName + "")); imgUpload.ImageUrl = "../UploadFile/" + strFileName + ""; //imgupload is the <img ID on which I am showing the image after upload imgUpload.Visible = true; } 上传文件后,我在项目解决方案中显示指定文件夹中保存的图像,但点击上传按钮后整个页面都被加载,我不希望单击上传按钮回发。