I have been going nuts all day trying to get a link button to fire its command event and cause a postback in a GridView control. On this particular page, whenever I click on the link, I get a WebForm_DoPostBackWithOptions instead of __doPostback, and of course I never hit the grid’s command event in my page behind.
The solution? Set causesvalidation=”false” in the link button and the command event will fire. Why, I don’t know, this just works and hopefully you’ll find this post before having to spend too many hours trying to figure it out.
Like this:
Be the first to like this post.
The following table maps .NET CLR datatypes with SQL Server parameters. The full Microsoft article is here.
| SQL Server data type |
CLR data type (SQL Server) |
CLR data type (.NET Framework) |
| bigint |
SqlInt64 |
Int64, Nullable<Int64> |
| binary |
SqlBytes, SqlBinary |
Byte[] |
| bit |
SqlBoolean |
Boolean, Nullable<Boolean> |
| char |
None |
None |
| cursor |
None |
None |
| date |
SqlDateTime |
DateTime, Nullable<DateTime> |
| datetime |
SqlDateTime |
DateTime, Nullable<DateTime> |
| datetime2 |
SqlDateTime |
DateTime, Nullable<DateTime> |
| DATETIMEOFFSET |
None |
DateTimeOffset, Nullable<DateTimeOffset> |
| decimal |
SqlDecimal |
Decimal, Nullable<Decimal> |
| float |
SqlDouble |
Double, Nullable<Double> |
| geography |
SqlGeographySqlGeography is defined in Microsoft.SqlServer.Types.dll, which is installed with SQL Server and can be downloaded from the SQL Server 2008 feature pack. |
None |
| geometry |
SqlGeometrySqlGeometry is defined in Microsoft.SqlServer.Types.dll, which is installed with SQL Server and can be downloaded from the SQL Server 2008 feature pack. |
None |
| hierarchyid |
SqlHierarchyIdSqlHierarchyId is defined in Microsoft.SqlServer.Types.dll, which is installed with SQL Server and can be downloaded from the SQL Server 2008 feature pack. |
None |
| image |
None |
None |
| int |
SqlInt32 |
Int32, Nullable<Int32> |
| money |
SqlMoney |
Decimal, Nullable<Decimal> |
| nchar |
SqlChars, SqlString |
String, Char[] |
| ntext |
None |
None |
| numeric |
SqlDecimal |
Decimal, Nullable<Decimal> |
| nvarchar |
SqlChars, SqlStringSQLChars is a better match for data transfer and access, and SQLString is a better match for performing String operations. |
String, Char[] |
| nvarchar(1), nchar(1) |
SqlChars, SqlString |
Char, String, Char[], Nullable<char> |
| real |
SqlSingle |
Single, Nullable<Single> |
| rowversion |
None |
Byte[] |
| smallint |
SqlInt16 |
Int16, Nullable<Int16> |
| smallmoney |
SqlMoney |
Decimal, Nullable<Decimal> |
| sql_variant |
None |
Object |
| table |
None |
None |
| text |
None |
None |
| time |
TimeSpan |
TimeSpan, Nullable<TimeSpan> |
| timestamp |
None |
None |
| tinyint |
SqlByte |
Byte, Nullable<Byte> |
| uniqueidentifier |
SqlGuid |
Guid, Nullable<Guid> |
| User-defined type(UDT) |
None |
The same class that is bound to the user-defined type in the same assembly or a dependent assembly. |
| varbinary |
SqlBytes, SqlBinary |
Byte[] |
| varbinary(1), binary(1) |
SqlBytes, SqlBinary |
byte, Byte[], Nullable<byte> |
| varchar |
None |
None |
| xml |
SqlXml |
None |
Hope this helps.
Like this:
Be the first to like this post.
Want to stop flickering when going from one page to another in AJAX?
Put the following code in your head section:
<head runat="server">
<meta http-equiv="Page-Enter" content="BlendTrans(Duration=.05)" />
<meta http-equiv="Page-Exit" content="BlendTrans(Duration=.05,Translation=0)" />
</head>
For more details about these meta settings, go to http://www.aim-higher.net/meta-transitions.asp.
Like this:
Be the first to like this post.
Something that has been bothering me for a really long time is now under control thanks to a blog post in the .NET Geek’s Blog entry on Understanding the Page Life Cycle in ASP.NET. In a nutshell, here is the issue. I prefer to create user controls that wrap standard .NET controls and then put role enabled and other code into the controls. That code determines if the control makes it self visible or disabled along with some other nice to haves.
The problem is that when a page first draws and fires off its events, the user control events follow, and if I come into the page wanting a button to be disabled in certian instances, the user controls resolve their states after the page. So if I have a button in a user control and expose its Enabled property through a get/set variable, I can never make it stick when the page first draws.
In the source code below, I am using the Page_PreRenderComplete event to test for page state and call an appropriate method. In this case the PrepUIforAdd is called and it disables a number of buttons as well other things. If I called PrepUIforAdd in the Page_PreRender event, the buttons would never stay disabled. But calling it in the Page_PreRenderComplete event will result in the outcome I want when the page displays.
/// <summary>
/// PreRender is complete
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_PreRenderComplete( object sender, EventArgs e )
{
if ( !Page.IsPostBack )
{
ucErrorMessage.Clear();
switch ( this.CurrentPageState )
{
case PageState.Add:
{
PrepUIforAdd();
break;
}
case PageState.Edit:
{
PopulatePersonInfo();
PopulateLinkedRoles();
PopulateUnlinkedRoles();
break;
}
}
this.ManagePersonTabContainer.ActiveTabIndex = 0;
}
}
/// <summary>
/// Preps UI for adding a person
/// </summary>
private void PrepUIforAdd()
{
this.txtPersonID.Text = (PersonIDConstant.Everybody.ToInt()).ToString();
this.txtLastName.Text = string.Empty;
this.txtFirstName.Text = string.Empty;
this.txtLogin.Text = string.Empty;
this.txtPassword.Text = string.Empty;
this.txtInceptionDate.Text = string.Empty;
this.txtLastModifiedDate.Text = string.Empty;
this.txtLastModifiedByPersonName.Text = string.Empty;
this.ddActive.YesNoID = 1;
this.ddDeleted.YesNoID = 0;
lbRolesAvailable.Clear();
lbRolesSelected.Clear();
this.bDelete.Enabled = false;
this.bNew.Enabled = false;
this.bResetPassword.Enabled = false;
this.bRoleLink.Enabled = false;
this.bRoleUnlink.Enabled = false;
ddEmailType.Clear();
List<EmailCollection> dt = GetCachedEmailList();
if ( this.ErrorLevel == Status.Success )
{
ddEmailType.DataSource = dt;
ddEmailType.DataTextField = "EmailTypeName";
ddEmailType.DataValueField = "EmailTypeID";
ddEmailType.DataBind();
}
this.txtEmail.Text = GetCachedEmailAddress( PersonIDConstant.Everybody.ToInt(), ddEmailType );
}
Like this:
Be the first to like this post.
I am using the AJAX Control Toolkit for its tab UI and my compile and link cycles came and went without incident on my Vista development machine. However when I deployed to our integrated unit test environment on Server 2008, I got the following error when accessing the page with tabs:
System.Security.SecurityException: Request for the permission of type ‘System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed. Here is a screen shot for reference.

I did a lot of checking and I found articles that involved accessing the AJAX Control Toolkit on a different machine, but that was not my issue. After publishing via Visual Studio to our server, all dll’s were in their normal folders.
The solution was to change one of the defaults on the application pool for this website. The value is under the Process Model section in Advanced Settings and is Load User Profile. By default it is set to false which will emulate IIS6 behavior of not loading the user profile for the application pool identity. Setting it to true solved the problem.

That was it. Make sure you recycle your application pool and restart your web site.
Like this:
Be the first to like this post.
Recent Comments