
PWNettle
Avatar/Signature-
Posts
129 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by PWNettle
-
You can't really control where Response.Write ends up, but you can give an element in your ASPX page an ID and a runat="server" so that you can manipulate it in code (ideally code behind). So as kahlua001 suggests, in your ASPX you might have (an asp.net label control inside an html paragraph element): <p><asp:label id="lblWhatever" runat="server"></p> An asp:label control is just an html span that's encapsulated as an object for ease of coding. It allows you to richly manipulate it via .Net code, but ultimately ASP.NET rendars an asp:label as an html span tag with appropriate attributes and styles based on how you've manipulated it in code. In your code it'd be declared in the appropriate section as: [csharp]protected System.Web.UI.WebControls.Label lblWhatever;[/csharp] Which would then enable you to bold using Kahlua001's suggestion or to do it more manually with: [csharp]lblWhatever.Text = "<b>ASP.NET is fun!</b>";[/csharp] Paul
-
Try: web1.Document.getElementById("fieldname").value = "testdata" Paul
-
I'm not really sure what it is that you're doing, but... Assuming that your dropdownlist's values are actually text (and not some numeric equivalent, you could add something like this (probably as a function since the dropdown value can change and you'll need to call the code when it changes). function changeMaxChars() var oDropDown = document.getElementById("ddMessage"); if (oDropDown.value == "Email") { MaximumCharacters = 500; } else if (oDropDown.value == "SMS" || oDropDown.value == "EMail & SMS") { MaximumCharacters = 160; } } On your dropdown list you'll need to add a javascript event handler (I think, if not then disregard) to fire the routine above, something like: <asp:dropdownlist id="ddMessage" runat="server" onchange="changeMaxChars();" /> onchange isn't an asp.net webcontrol event so there's no risk of conflicting with asp.net when you add that into the asp.net webcontrol declaration. Good luck, Paul PS - That javascript you posted makes me cringe, especially the misuse and abuse of eval(). I'd recommend writing your own script if at all possible!
-
Regular Expression Validator - Illegal characters
PWNettle replied to kristoffera's topic in Regular Expressions
Validator controls seem to not fire at all if the target control is empty. So, sadly, if you want to validate by regular expression and want the field to be required (no empty strings) then you may need to use two validators - a regular expression validator and a required field validator. I think custom validators always fire - so you can duplicate the functionality of both in one custom validator - but to me this seems like a poor solution (as in, it seems like one shouldn't have to do this). If someone knows a way around this I'd be glad to hear/read it because using two validators in this type of situation irks me! Paul -
Regular Expression Validator - Illegal characters
PWNettle replied to kristoffera's topic in Regular Expressions
Sure - you just have to construct your regular expression properly. You might refer to "regular expressions, syntax" in MSDN for a list of all the characters and symbols one can use in a regular expressions. For ex: [^a-c] matches any character that's not a through c, but chances are you'll need more than just that to accomplish whatever you're after. Paul -
Assuming you have properly declared the checkbox in your code, and assuming that you're properly setup the control in your .aspx (by setting runat=server and giving the control an 'id' tag) then regardless of whether you're using an ASP.Net Checkbox webcontrol or an HtmlInputCheckbox you would set its 'Checked' property. chkControlName.Checked = True chkControlName.Checked = False Paul
-
If by 'Header Height' you're referring to the title bar, then you can use: SystemInformation.CaptionHeight Paul
-
Are you setting the 'From' property on your messages? I would guess that your mail client marks emails as bulk based on subject text or sender moreso than the server that it comes from (unless it's been configured to know that particular IPs are spammers, which is unlikely for your localhost). Paul
-
There are several ways you can accomplish this. One commonly used way is to use the Session object, which you might use (after a successful login) like: [csharp]// where sUsername is a string holding the username // where nUserId is an int holding the user's ID number Session.Add("username", sUsername); Session.Add("userid", nUserId);[/csharp] It's up to you what you store off for user info. Session can hold objects too so if you have a user object you could store the entire user object off if you wanted to. You can get values out of session just as easily: [csharp]string sUsername = Session["username"]; int nUserId = Session.Contents["userid"]; // variation[/csharp] Sessions can expire so you'll usually want to check for nulls or wrap a try/catch around the code that grabs the values. In a robust app you might have the user re-login if their session expire. Another similar way to track user info is with cookies. Cookies are a little more flexible. Cookies are always stored on the client machine (Sessions can be setup for different storage mechanics, but it's often server-side storage). A simple cookie example: [csharp]HttpCookie oCookie = new HttpCookie("logininfo"); oCookie["username"] = sUsername; oCookie["userid"] = nUserId; oCookie.Expires = DateTime.Now.AddHours(2); Response.Cookies.Add(oCookie);[/csharp] And to retreive values: [csharp]HttpCookie oCookie = Request.Cookies["logininfo"]; string sUsername = oCookie["username"]; int nUserId = int.Parse(oCookie["userid"]);[/csharp] And again - you usually want to check for null or use a try/catch because cookies can expire too. The syntax would be similar if you're using VB.Net. For more info on either, refer to MSDN, google, or search around here. Paul
-
One way is to use the System.Diagnostics.Process object, for ex: [csharp]// C# Example System.Diagnostics.Process oProcess = new System.Diagnostics.Process oProcess.Start("http://www.somedomain.com");[/csharp] ' VB.Net Example Dim oProcess As New System.Diagnostics.Process oProcess.Start("http://www.somedomain.com") It'll launch the URL into the default browser. Paul
-
Your thinking should work as long as you use the same type of object throughout (I'm not sure about the casting potential between Image and Bitmap objects - for ex, putting an Image object in the hashtable and then trying to cast it to a Bitmap object might not work). I also don't see why you'd put brackets around the key (myHashtable.add(["pic1"],...) since that doesn't even compile (maybe that's just the way you typed it here...). Hashtables store everything as type Object so you'll usually need to explicitly cast the contents when you want to use them. So, either do both as Bitmaps: myHashtable.Add("pic1", new Bitmap("path")); Bitmap picture = (Bitmap) myHashtable["pic1"]; Or as Image objects: myHashtable.Add("pic1", Image.FromFile("path")); Image myImage = (Image) myHashtable["pic1"]; PictureBox1.Image = myImage; (I tried the Image object variant above on a .jpg image and it worked fine...)
-
I'm not a regex fanatic but I think the use is appropriate here. Why use 10 lines of code to handle a specific situation when 3 lines of code that are much more flexible do the job? In this case the regex use is extremely simple, it's not like a highly complex pattern is in use or isolating substrings is occurring. In your sample you create a structure and a special function that converts text to char, loops, and processes - and you're saying using regex is overkill? Ok... On any machine that can run .Net reasonably well I seriously doubt the performance hit of using regex is going to be an issue.
-
One way to do this would be to use a regular expression - or more specifically use the Replace method of a regular expression object. Here's a C# example...the VB.Net syntax would be very similar: Regex oRegex = new Regex(@"\D"); string sTest = "abcXYZ123abc"; sTest = oRegex.Replace(sTest, ""); MessageBox.Show(sTest); // displays "123" The pattern for the regex is setup as "\D" (in C# that @ before the string literal tells C# to take the string contents literally, since backslash in an escape character otherwise - I don't think you'd need that @ in VB.Net), which indicates to match any non-digit character. That pattern is applied to the target string when the Replace method is invoked, and in this case each non-digit occurance is being replaced with an empty string, so you end up with a string stripped of all non-digit characters. For more help with regular expressions you might visit that particular forum here or check out 'regular expressions, syntax' (and other topics) in MSDN. Good luck, Paul
-
I'm from a land where "r" and "u" are letters, not words. :-/ I think it's more commonly known as the land of old age. :p
-
Another option might be to create a virtual mapping to only your "includes" folder off the root - that way any project you create could link to it with "/includes/..." regardless of where it was in the virtual heirarchy. A server can host multiple sites, for sure, but that doesn't mean that you as a developer will run a development environment that works the same way (and hopefully you develop seperate from your live sites!) It might depend on what operating system you have, what web server you have, and what your network will let you get away with.
-
If you're happy with how it's working on the "live" site then you probably should alter how your development environment is behaving so that it mimics your live environment. Change the physical location of your IIS root mapping to be your project's physical root folder. Right now your dev IIS virtual root is (most likely) mapped to: c:\inetpub\wwwroot Change it to: c:\inetpub\wwwroot\yourproject ...if your physical files are actually off of wwwroot, otherwise change it to whatever path contains your project files (IIS doesn't care what its root is mapped to - I change my root mapping so much for different code bases that I created a task bar tool to do it so I don't have to use the clunky management console). One you've changed the IIS virtual root to point directly to your project you can get to your project as "http://localhost" and all your root relative URLs will work properly. Paul PS - One extra word - if you haven't messed with changing your root when doing ASP.Net _and_ if you use ASP.Net validators then you'll want to make a virtual mapping for the aspnet_client folder that physically exists under c:\inetpub\wwwroot. Once you've made this mapping once it'll persist whenever you change the root around. ASP.Net's validator javascript is in that folder so validators won't work if it's not available.
-
I think you're looking for: e.Handled = True (e is the event args object of the event) ...which essentially cancels the event (the key press). Any code you have in the event will execute, but they key press is surpressed. Paul
-
Any interest for an INI class wrapper?
PWNettle replied to cincyreds's topic in Directory / File IO / Registry
I deal with quite a bit of Xml but I'm not Xml efficiency expert. I have had similar thoughts regarding the efficiency of xml objects compared to other I/O but in my experience the stuff seems ridiculously fast. I often deal with 20,000+ characters at a time from webservice feeds or files and I never notice any kind of load lag. So, I imagine with a relatively small file you really wouldn't notice any speed or memory issues. I'd imagine the experts here could provide better info and/or you might find some performance stats online somewhere. Good luck, Paul -
Any interest for an INI class wrapper?
PWNettle replied to cincyreds's topic in Directory / File IO / Registry
-
The simple response is to use javascript in a button: <input type="button" value="back" onclick="history.back();"> However, if you're page has been "refreshing" via numerous postbacks then you'd actually need to use: "history.go(-x)" (which will enable your page to truly back up to the previous page rather than backing thru all the postbacks) where "x" is a counter you maintain in your codebehind based on how many times you've done postbacks (need to store the value between postbacks in ViewState or something). In this type of situation you'd probably want your button to be setup to runat=server so you could dynamically create the javascript "onclick" event to include the "back count". Paul
-
I don't think that's really true...it's more of a stylistic thing... This: private void button1_Click(object sender, System.EventArgs e) { TreeNode oNode = this.treeView1.SelectedNode; if (oNode != null) { SelectNodeAndParents(oNode); } else { MessageBox.Show("You must select a node first"); } } And this: private void button1_Click(object sender, System.EventArgs e) { if (this.treeView1.SelectedNode != null) { SelectNodeAndParents(this.treeView1.SelectedNode); } else { MessageBox.Show("You must select a node first"); } } ...should be the same. I've just adjusted to the style most commonly used where I work - we tend to create a simple reference (like 'TreeNode oNode' in the first snippet) if we're going to refer to a reference often rather than using the more lengthy references (like 'this.treeView1.SelectedNode), because our custom objects can often have some lengthy names, especially when dealing with multiple levels of subobjects. But anyways, if it works it's all good - and apologies if I insulted your intelligence with the bit about populating and making sure a node is selected - I was only attempting to be thorough! Pardon the rambling. ;) Paul
-
The SelectedNode property is a reference to the currently selected node, so if no node is selected, it's a null reference. So... The most likely cause of this is that either your treeview has no nodes or there is no node selected from the treeview's nodes. Either way, it's a good idea to check the SelectedNode property to see if it's null (not currently holding a reference to a node) before using it, for ex: private void button1_Click(object sender, System.EventArgs e) { TreeNode oNode = this.treeView1.SelectedNode; if (oNode != null) { SelectNodeAndParents(oNode); } else { MessageBox.Show("You must select a node first"); } }
-
Unless you need to do a postback (or do some server-side processing to determine the button targets) then you might as well just use javascript with your buttons to "direct" to another page, for ex: <input type="button" value="Private" onclick="window.location.href='trader.asp';"> If you need to determine the target pages for the buttons before displaying them then you might use an input or asp:button with runat=server and set them up with the javascript event via their attributes collection the first time your page is hit. (Doesn't sound like you need it in this case.) Good luck, Paul
-
I imagine this topic has been covered before...but here goes anyways... In C# you can alter your winapp's entry point (Main() routine by default) to allow it to accept command line arguments like so: (this code is autogenerated in your winform's code) /// <summary> /// The main entry point for the application. /// </summary> [sTAThread] static void Main([b]string [] sArgs[/b]) { Application.Run([b]new Form1(sArgs)[/b]); } All you have to do is provide this simple way for your app to receive the command line arguments (usually done via a string array to allow for a potentially varying number of arguments). Windows will automatically pass in the command line values for you. You could deal with your command line arguments in Main...but in the example above the args are passed on to the form's constructor, which has been similarly altered for accepting the args: public Form1([b]string [] sArgs[/b]) { InitializeComponent(); for (int i = 0; i < sArgs.Length; i++) { this.label1.Text += sArgs[i] + Environment.NewLine; } } The easiest way to setup an icon to fire your winapp with command line arguments is to make a shortcut to for your EXE and edit the shortcut properties to include the command line arguments. The "target" of your shortcut should be the full path to your EXE. Just stick your arguments after that (seperated by spaces). If you want to pass in an argument that contains spaces put it inside double quotes. Paul PS - If C# isn't your thing I'm sure this can be done almost exaclty the same in VB.Net.
-
A simple approach would be to use standard file I/O to create a text file and to save your values as comma delimitted text within that file. Give the file an extension of ".csv" and it'll open up directly into Excel as is.