I have a datalist with 2 columns of products with a TextBox next to each product so my customer can enter a number in each checkbox (to determine the order sequence when this list of products is printed to the screen). I have a button for my customer to click when she is happy with the sequence chosen for each product and this calls a subroutine within which I need to be able to collect each productID and the number entered into the textbox next to it. This worked perfectly in my old system using Classic ASP and can't understand why it's so difficult to offer the same funtionality in ASP.Net! I have tried various approaches but none of them work in collecting the number entered into the TextBox and the ProdId at the same time. I tried storing the ProductId in the ID of the TextBox in the hope that I could then retrieve both the ProductId and the value of the TextBox for each product when the button is clicked but values of the TextBox ID are values such as 567 or 784 and are set dynamically (these are the productIds). The error I'm getting is as follows: The ID property of a control can only be set using the ID attribute in the tag and a simple value. Example: and the line containing the error is: Any advice would be greatly apreciated. Thanks, Lorna
User 3400231
Posts
-
DataList: Collecting IDs and TextBox values at same time -
Assigning and retrieving values from checkboxes which are dynamically created.Thanks but I'm just navigating through a directory and adding each filename to an ArrayList, I then bind the list to the DataList so somehow need to get the filename. I tried assigning the filename to the Name property using Name="<%# Container.DataItem %>" but when I wiew the source I get: name="dlImages$ctl09$cb3"?? So any ideas would be appreciated.
-
Assigning and retrieving values from checkboxes which are dynamically created.I am dynamically displaying thumbnail images from a folder but under each image, I have a checkbox -this is so the user can click a checkbox for each image he/she wants to delete and then click the submit button. However, I know I can get the values of checkboxes checked (true/false) but I need the filename of the image above it so I know which image to delete. I tried assigning the filename to the id of each checkbox but I get the error: "The ID property of a control can only be set using the ID attribute in the tag and a simple value." My code is as follows:

and I am binding an ArrayList of filenames on Page_Load. Any ideas would be much appreciated. Thanks Lorna
-
Directory.GetFiles - how do I get the file names only and not the complete path?Hurray it works! Thank you very much. For any other interested parties, I rewrote as: DirectoryInfo dir = new DirectoryInfo(@Server.MapPath("~/administration/uploaded/")); foreach (FileInfo file in dir.GetFiles()) { imageNames.Add(file.Name); } Which gave me an ArrayList of filenames only (no path).
-
Directory.GetFiles - how do I get the file names only and not the complete path?Thanks but is that not the same as what I have and I get the complete path - here is another 2 lines of the code: ArrayList imageNames = new ArrayList(); string imagesDir = Server.MapPath("~/administration/uploaded/"); foreach (string img in Directory.GetFiles(imagesDir, "*.jpg")) { imageNames.Add(img); } thanks Lorna
-
Directory.GetFiles - how do I get the file names only and not the complete path?I have the following code which stores the filenames in an array. However, I want only the filenames to be stored. Surely there is an easy way to do this? I know I can replace the line, imageNames.Add(img); with imageNames.Add(img.Remove(0, 22)); which will remove the path (first 22 chars) leaving just the filename but this will be different when I upload to my server so don't really want to do it this way. Any ideas will greatly appreciated. foreach (string img in Directory.GetFiles(imagesDir, "*.jpg")) { imageNames.Add(img); } Many thanks Lorna
-
File.Exists - cannot find file on PostBackHi I'm writing a web app to upload up to 4 images to a folder. I also have a drop-down list so the user can choose whether pic is picture 1, 2, 3 or 4 (to set order on page display). Anyway, when one picture is uploaded the user stays in the form to add more pictures. I clear the DDL and re-populate it depending on which pictures have already been uploaded - i.e if pic 1 has been uploaded, only pic 2, 3 and 4 appear in drop-down. To determine this I use File.Exists but this doesn't seem to be working on a postback (i.e it doesn't find pic1.jpg which I have uploaded. It works however, if I leave the page and then click to add an image later - could this be an issue of the folder not refreshing so it looks like the file doesn't exist or a postback problem? Any ideas would be greatly appreciated. Thanks Lorna
-
File.Exists - not finding file on PostBackOK will do, but I am using c# code to do this!
-
File.Exists - not finding file on PostBackHi I'm writing a web app to upload up to 4 images to a folder. I also have a drop-down list so the user can choose whether pic is picture 1, 2, 3 or 4 (to set order on page display). Anyway, when one picture is uploaded the user stays in the form to add more pictures. I clear the DDL and re-populate it depending on which pictures have already been uploaded - i.e if pic 1 has been uploaded, only pic 2, 3 and 4 appear in drop-down. To determine this I use File.Exists but this doesn't seem to be working on a postback (i.e it doesn't find pic1.jpg which I have uploaded. It works however, if I leave the page and then click to add an image later - could this be an issue of the folder not refreshing so it looks like the file doesn't exist or a postback problem? Any ideas would be greatly appreciated. Thanks Lorna
-
HELP!! DropDownList not displaying first recordThanks but I'm using the if (objRdr.Read()) to check that records have been returned as sometimes there will be no records - is there another way to check this before using DataBind?
-
HELP!! DropDownList not displaying first recordI was about to publish my site live until I discovered that a DDL is not displaying the first record from the results set! My code is as follows: if (objRdr.Read()) { ddlModelTypes.DataSource = objRdr; ddlModelTypes.DataValueField = "TypeId"; ddlModelTypes.DataTextField = "ModelType"; ddlModelTypes.DataBind(); } I thought the following line was replacing the first value: ddlModelTypes.Items.Insert(0, "Other"); However, I took this out and it's still not displaying the first record value so any help will be much appreciated. Thanks Lorna
-
CustomValidatorHi I'm a newbie c# programmer and have written a custom validator to validate 2 controls on a web form. I have other controls too on the same form which use the standard ASP.Net validation controls and they work perfectly however, although my custom validator works and writes the error messages to the web form, it also wants to fire off the addVehicleToDB method which is called by clicking the Submit button. This is ok of course if data entry is correct but it happens even when e.IsValid = false;! Obviously I am not fully understanding the order in which events happen so if someone could point me in the right direction that would be great. Here is my custom validator function which is linked to a text box: public void ValidateModelType(Object s, ServerValidateEventArgs e) { lblNoType.Text = "got here"; //if the text box is null if (e.Value == "") { //check that model type has been selected from drop-down list if (ddlModelTypes.SelectedItem == null) { lblNoType.Text = "not valid!"; e.IsValid = false; } else { lblNoType.Text = "all ok"; e.IsValid = true; } } } Thanks Lorna
-
SPROC: Insert only writing first char into a varchar (15) field??Thanks - that was the problem (I knew it would be something obvious :-)) I actually had int = 4 in other SProcs so I've changed those values to just int now in case anyone else is interested and they all work fine.
-
SPROC: Insert only writing first char into a varchar (15) field??Hi I have written a stored procedure as follows: ALTER PROCEDURE dbo.VehiclesInsert ( @TypeId int = 4, @Reg varchar = 15, @Mileage decimal = 9, @Price money = 8, @Fuel int = 4, @Colour varchar = 80, @BodyShape int = 4, @Doors int = 4, @Warranty int = 4, @MoreInfo text, @RegLetter int=4, @CreatedBy int=4 ) AS INSERT INTO Vehicles (TypeId,Reg,Mileage,Price,Fuel,Colour,BodyShape,Doors,Warranty,MoreInfo,RegLetter,CreatedBy) VALUES (@TypeId,@Reg,@Mileage,@Price,@Fuel,@Colour,@BodyShape,@Doors,@Warranty,@MoreInfo,@RegLetter,@CreatedBy) RETURN Although I have defined the Reg variable as Varchar 15, it only writes the first letter into the Reg field of my DB. I am using ASP.NET and c# to call the sproc - I even tried hard-coding the parameter value e.g: objCmd.Parameters.Add("@Reg", "Test Reg"); However it still only adds "T" into the Reg field. I can manually add Test Reg into the field in the DB table so the field lengths all seem to be ok. I'm very new to SProcs so please excuse me if I'm missing something obvious! Thanks Lorna
-
Classic ASP and Web Developer ExpressHi I'm in the process of converting my classic asp websites into ASP.Net (c#). I have set up a website in Web Developer Express but when I run an .asp page in the browser, I get an error message: This type of page is not served. Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.asp' may be incorrect. Please review the URL below and make sure that it is spelled correctly. Do I have to tell Web Developer Express that I am running .asp pages? I have set the website up to run ASP.NET pages because that's what I'm converting them to but will need to also run some .asp pages in the meantime. Thanks Lorna
-
The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).Hi there I have a page with a DDL which binds the data in the .aspx page rather than the code behind. It was all working nicely until I moved this page onto another computer - it was working on one with Visual Web Developer Xpress but now it won't work on Visual Studio 2005. I thought maybe it is because the versions of .Net are different. I'm a newbie so please don't patronise! Here is a snippet of my code:
Please someone help me! Lorna
-
Problem saving a resized image - HELP!!Thanks - tried that but get message: CS0165: Use of unassigned local variable 'thumbNailImg' on line: thumbNailImg.Save(fullPath); Thanks Lorna
-
Problem saving a resized image - HELP!!I am using populating a ListBox with the files I want to resize and when the user clicks a button, the method goProcessImages is called and I traverse through each one resizing it (well I'm trying to!). Thanks - here is my code behind (sorry it's a bit of a mess but I've been commenting out things to find out what's going wrong): using System; using System.Collections; using System.Configuration; using System.Drawing; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.IO; public partial class ResizeImage : System.Web.UI.Page { ArrayList imageNames = new ArrayList(); string imagesDir = "D:\\Website\\BookImages\\"; //get path of Books dir in website protected void Page_Load(object sender, EventArgs e) { string imgForLB = ""; if (!IsPostBack) { int i = 0; try { foreach (string img in Directory.GetFiles(imagesDir, "*.jpg")) { imageNames.Add(img.Remove(0, 22)); } foreach (string img in Directory.GetFiles(imagesDir, "*.jpeg")) { imageNames.Add(img.Remove(0, 22)); } foreach (string img in Directory.GetFiles(imagesDir, "*.gif")) { imageNames.Add(img.Remove(0, 22)); } } catch { Response.Write("We are currently experiencing problems in obtaining images from the directory " + imagesDir + "Make sure you are offline and this directory exists on your laptop and it is not empty."); } //write out image names to screen for Angell to check for (i = 0; i < imageNames.Count; i++) lbFileNames.Items.Add(imageNames[i].ToString()); } } // Required by GetThumbnailImage() method, but not used public bool ThumbnailCallback() { return true; } protected void goProcessImages(object sender, EventArgs e) { string imageName = ""; //resize each file listed in listbox foreach (ListItem item in lbFileNames.Items) { imageName = item.ToString(); if (imageName != "") { //createThumbnail(imageName, 400); createThumbnail(imageName, 100); } } } protected void creat
-
Problem saving a resized image - HELP!!Yes and I'm sure it was working yesterday although I have extended my code a bit :confused:
-
Problem saving a resized image - HELP!!I'm a newbie to all this (so please bear with me :-)) - I found the vb version of this code on the web and attempted to rewrite as C#. I thought I was creating a new instance in this line: System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero); If not, please tell me how. Many thanks Lorna