Here is some old code I found (in VB.NET) the will tell you what control caused the post back.
' Return a reference to the control that caused the last postback,
' even from the Page_Load event!
' It requires in input a reference to the posted-back page
' (this is necessary if you want to be able to move this function in a separate
' instead of in a page's codebehind class
' Private Sub Page_Load(ByVal sender As System.Object,
' ByVal e As System.EventArgs) Handles MyBase.Load
' Dim postbackCtl As Control = GetPostbackControl(Me)
' If Not postbackCtl Is Nothing Then
' lblResult.Text = postbackCtl.ID
' End If
' End Sub
Function GetPostbackControl(ByVal targPage As Page) As Control
If targPage.IsPostBack Then
' try to find the name of the postback control in the hidden
' __EVENTTARGET field
Dim ctlName As String = targPage.Request.Form("__EVENTTARGET")
' if the string is not null, return the control with that name
If ctlName.Trim().Length > 0 Then
' the trick above does not work if the postback is caused by standard
' In that case we retrieve the control the ASP-way: by looking in the
' Page's Form collection
' to find the name of a button control, that actually is the control
' that submitted the page
Dim keyName As String
For Each keyName In targPage.Request.Form
Dim ctl As Control = targPage.FindControl(keyName)
' if a control named as this key exists,
' check whether it is a button - if it is, return it!
If Not ctl Is Nothing Then
If TypeOf ctl Is Button Then
Here is a generic send mail method.
You just need to pass in a subject and body.
In your web.config you need a key for the from (notification_from), To (notification_to) and mail server (mail_server).
You could easily alter it to move the to (or from) to input variables.
private static void sendNotification(String Subject, String Body)
MailMessage mailMessage = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string msg = string.Empty;
String from = ConfigurationManager.AppSettings["notification_from"];
String to = ConfigurationManager.AppSettings["notification_to"];
String mailserver = ConfigurationManager.AppSettings["mail_server"];
MailAddress fromAddress = new MailAddress(from);
mailMessage.From = fromAddress;
mailMessage.Subject = Subject;
mailMessage.IsBodyHtml = true;
mailMessage.Body = Body;
smtpClient.Host = mailserver;
smtpClient.EnableSsl = false;
smtpClient.UseDefaultCredentials = true;
The .NET framework has a cool feature called the Ternary Operator. It’s basically a shortcut for an if/then/else statement.
Here’s the format:
condition ? first_expression : second_expression;
The condition must be something that evaluates to true or false. The first expression is what get’s returned if the condition is true. Obviously the second expression gets returned if the condition is false.
I make use of then when I’m pulling data from a source and loading an object (ie, handle null from the source).
So here we have a normal check for null. If it is null then set the property to String.Empty otherwise set to the value.
if (FirstName == null)
emp.FirstName = FirstName;
Here is the same statement using the new format.
emp.FirstName = (FirstName == null) ? String.Empty : emp.FirstName = FirstName;
Much more compact code.
Remember you need both the ? and :
Don’t forget those.
Click once applications have many advantages and disadvantages.
One of the disadvantages is that it hides where the application gets installed. So if need to double check something like a connection string in your config file it can be a pain.
So next time you need to know where you application is this might help.
C:\Documents and Settings\[username]\Local Settings\Apps\2.0\[some
folder]\[some other folder]\manifests
The load test in Visual Studio are a great help to stress/performance test you applications. With the web test you “should” be able to record actions as you use your application. When you add a web test IE starts and there should be recorder bar on the left.
When ever I created a web test I never saw the web test recorder bar show up. I didn’t even know I was missing it. So, I was never able to get to do anything besides record that you launched a page which helps you test page load time, but doesn’t help you when your trying to determine the response time when clicking a button on your page.
After a little research (little as in there are few articles explaining this problem), I found a blog post explaining why the web test recorder not working. It turns out to be a 64-bit issue. There are some registry keys that need to be deleted, so IE will rebuild what explorer bars are available.
Here is the link to the article.
The short version is close all IE’s, run regedit, then delete the following keys
When using the Visual Studio integration for TFS 2008, you will notice that the latest version will not be retrieved when you start making changes to a file.
There is an option that you need to have an option. To get to this option perform the following steps:
Launch Visual Studio 2008
Expand the Source Control section
Click on Visual Studio Team Foundation Server
Ensure that the Get Latest version of item on check out is checked.
Now when you check out a file if you don’t have the latest version, it will prompt that you don’t and fetch it for you.
When I first started blogging I wanted to blog on asp.net. I have a friend who already blog’s on asp.net (David Mccollough) and I asked him what the steps were (because they are not on asp.net).
Here is what he told me.
Well it’s a multistep process.
1st you have to create an account to be able to login, which I assume you have already done.
4th Before you first post you need to read this: http://www.misfitgeek.com/WeblogsaspnetNewBloggerFeedGrowth.aspx
Here is the original link to his blog post that outlines the process: http://www.misfitgeek.com/2008/06/16/JoinUsWithABlogOnWeblogsaspnet.aspx
The test tools in Visual Studio can help you stress test your application. The only problem is that they are not included with the regular developer edition of Visual Studio. So if have the wrong version installed you need to uninstall and reinstall a version that does have those project types (like Team Suite).
What I found though was after you uninstalled and reinstalled you were not able to open/create test projects.
The project types were there, but you receive an error: The following project languages must be installed C#, C++, VB.NET (or something like that). Everything else will work, but the test project template.
What you have to do in go to Control Panel –> Programs and Features (or add/remove programs) and do a Repair/Reinstall on your install of Visual Studio.
After that finishes you can now open/create test projects.