c#-3.0

Keep Focus back to the previous Textbox on failed validation

半城伤御伤魂 提交于 2019-12-13 04:39:29
问题 I want Focus back to the previous Textbox if validation gets failed. I am validating the Textbox control value on lostFocus event. Need some help. This question was eralier too link is Keep Focus on Textbox after user tried to move to other control (on failed validation) in winforms, .net 3.5 WEC7 回答1: If you attempt to focus an element inside its own LostFocus handler you will face a StackOverflowException , I'm not sure about the root cause (I suspect the focus kind of bounces around) but

Need to call jQuery (window).load(function ()) using c#

只谈情不闲聊 提交于 2019-12-13 03:31:38
问题 I need to call the (window).load(function ()) using C#. Is there anyway that I could accomplish this. 回答1: Register whatever script you want with RegisterStartupScript: protected void Page_Load(object sender, EventArgs e) { // Define the name and type of the client scripts on the page. String csname1 = "PopupScript"; Type cstype = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; // Check to see if the startup script is

Filter input from keyboard in Textbox, C#

我怕爱的太早我们不能终老 提交于 2019-12-13 02:49:33
问题 I want to filter the keyboard inputs into textbox based on the type of input I allow. e.g. 0 for Digits only 1 for Alphabets only 2 for Alphanumerics So if 0 is configured and a character 'a' is pressed on the keyboard, it is not shown in the textbox. How do I do that in C#? Thanks 回答1: You need to subscribe to control's KeyPress event (and optionally KeyDown method), and if key stroke must be eaten set Handled property to true. Read more in msdn (with sample that cover your problem). 回答2:

unregister an .ocx in 'onbeforeinstall' event of Installer class then try to register it on install but couldnt done

馋奶兔 提交于 2019-12-13 02:32:04
问题 Hi , I tried to unregister and delete an .ocx & a .dll from the System32(XP 32 bit os)/SysWow64(64bit OS) of the machine using C# code. I had written the Unregister & Delete code in the override method OnBeforeInstall(IDictionary savedState) of installer class.When I tried to install the .msi the files(.ocx & .dll) get Unregistered, but at the install completes the new files not get registred ie its not present in the System32 folder. Is the OnBeforeInstall event deletes the new files? Please

How do I tell if the ObjectDataSource OnSelected event was called for the selectmethod or selectcountmethod?

我的未来我决定 提交于 2019-12-13 00:38:28
问题 I have an object datasource that looks like this: <asp:ObjectDataSource ID="obdsList" runat="server" EnablePaging="True" SelectCountMethod="GetCountByID" SortParameterName="sortExpression" OldValuesParameterFormatString="original_{0}" SelectMethod="GetByID" TypeName="Services.Users" onselected="obdsList_Selected"> <SelectParameters> <asp:QueryStringParameter Name="ID" QueryStringField="ID" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource> And a onselected event like this: protected

C# anonymous type foreach looping

浪子不回头ぞ 提交于 2019-12-13 00:27:19
问题 I need to loop through the properties of a custom object type that I'm getting back from the database and only show the columns that contain data. This means I cannot simply bind the list of objects to the datagrid. I don't want to loop through each object and see if the column is empty/null and determine in the UI to display it. What I'm thinking is in my business layer before I send the object back I would send an IEnumerable back with only those columns that should be visible. Thus I was

System.Reflection

余生长醉 提交于 2019-12-12 23:12:33
问题 let us consider im having an application AAA. From my application im loaded an assembly named as BBB.When im in BBB path, i need to get the AAA Assembly name at run time. how to accomplish this? Thanks in advance 回答1: The call to: Assembly.GetExecutingAssembly() will return the assembly it's written in (the currently executing assembly). Or in your case, maybe you'll need: Assembly.GetEntryAssembly() to get the executable assembly (the assembly that the application was started with). 来源:

Exporting data to excel file C#.NET

狂风中的少年 提交于 2019-12-12 20:27:15
问题 I want to export the data from a access database to excel file. But i got Exception from HRESULT: 0x800A03EC error. Here is a bit of code that i have written, using System; using System.Data; using System.Data.OleDb; using System.Configuration; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Text; using System.Windows.Forms; using Excel = Microsoft.Office.Interop.Excel; private void showBtn_Click(object sender, EventArgs e) { int cnt = -1;

Deserialize from MemoryStream throws OutOfMemory exception in C#

心已入冬 提交于 2019-12-12 19:58:02
问题 This is a C# 3.0 Winform problem. I want to clone a big(not very big actually), complicated object. To do it lazily, I seralize it to a MemoryStream and use BinaryFormatter.UnsafeDeserialize(MemoryStream, null) method to get the cloned object. Inside the UnsafeDeserialize() method, there is always an OutOfMemory exception thrown. The memory should be sufficient. I read a bit about this as a .net bug but not sure whether it is the case here. Anyone has any idea why this is happening? Any

ASP.NET Membership staying authenticated issues

隐身守侯 提交于 2019-12-12 14:19:43
问题 So, my application is being odd in the fact that when you login you will stay logged in for a page or two then get lost. My settings are this: <authentication mode="Forms"> <forms name=".ASPXFORMSAUTH" timeout="20"/> </authentication> <authorization> <allow users="*" /> </authorization> <membership defaultProvider="MySqlConnection" userIsOnlineTimeWindow="45"> <providers> <clear /> <add name="MySqlConnection" type="System.Web.Security.SqlMembershipProvider" connectionStringName=