Thursday, February 26, 2009

IE8

I upgraded to IE8 recently and it seem to be much smarter. However it does not display my websites the same way.

From what I have seeem it tends to disply more along the line of firefox as oppose to IE7

Some browser differences for validation controls

For IE when i disable a control it takes the validation control out of play, but when I run the same file in songbird it does not work. It is not visible but it interferes with the submitting of the form.

When I set the visible property of the validation control to disable then it works.

Tuesday, February 17, 2009

How to Fing Control in EmptyData Row in Gridview for VB.NET

It's simple but not very intuiative.

VB.NET
gvDisplay.Controls(0).Controls(0).Controls(0).FindControl("controlid")

Friday, February 13, 2009

VB.NET turn links cursor into text cursor

Sometimes vb.net application will turn the curesor for links (pointer) into text cursor (I).

I find that if you specifically specify the a tag to a pointer then it will fix that problem.

a
{
cursor:pointer;
}

.NET Request object properties

Request Property Function and Example
  • ApplicationPath -Returns the a Web server relative path to your application root /WestwindWebStore/

  • PhysicalApplicationPath -
    Returns a local file system path to your application root D:\inetpub\wwwroot\WestWindWebStore\

  • PhysicalPath - Returns the full file system path to the currently executing script D:\inetpub\wwwroot\WestWindWebStore\Item.aspx

  • CurrentExecutionFilePath - FilePath

  • Path - In most situations all of these return the virtual path to the currently executing script relative to the Web Server root. /WestwindWebStore/item.aspx

  • PathInfo - Returns any extra path following the script name. Rarely used – this value is usually blank. /WestwindWebStore/item.aspx/ExtraPathInfo

  • RawUrl - Returns the application relative URL including querystring or pathinfo
    /WestwindWebStore/item.aspx?sku=WWHELP30

  • Url - Returns the fully qualified URL including domain and protocol
    http://www.west-wind.com/Webstore/item.aspx?sku=WWHELP30

  • Page.TemplateSourceDirectory - Control.TemplateSourceDirectory
    Returns the virtual path of the currently executing control (or page). Very useful if you need to know the location of your ASCX control instead of the location of the page. /WestwindWebStore/admin


Above copied from http://www.west-wind.com/weblog/posts/269.aspx

Link to the application root
use Request.ApplicationPath

Thursday, February 12, 2009

Set Focus to textbox after updatepanel updates

VB.NET

I have a gridview in a update panel displaying a set of records. When I select a record I want to set focus to a text box. This following script will do that

Set the following cod under the script manager or you will get the sys object not found error

<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
//Use timer so that the script will wait .5 sec before it fires to let page complete rendering the txtDSChartNumber element
setTimeout ( 'setFocus(\'txtDSChartNumber\')', 500 );
}
function setFocus(controlid) {
if (document.getElementById(controlid)){
document.getElementById(controlid).focus();
document.getElementById(controlid).select();
}
}
</script>

Wednesday, February 11, 2009

Call server function without post back using ICallbackEventHandler

Steps

  1. Implements the ICallbackEventHandler in the partial class of the code behind file.

  2. Create a client script in the aspx page to be called from server so result can be returned

  3. Use the ClientScriptmanager to get a reference to the client script you created

  4. ClientScriptmanager. RegisterClientScriptBlock fucntion
    • a. to register the callback script that is used by the client elements to call the server

    • b. to register the script reference we got for step3
  5. Create the RaiseCallbackEvent sub that is used to retrive client arguemnts

Thursday, February 05, 2009

Retriving Identity Value after Insert

Database: Microsoft SQL Server
Program IDE: VB.NET 2005

I want to retrive the auto generated identity value after I insert a record into an identity column.

There were a lot of stuff about it but nothing that work work without using a stored procedure.

Basically I enclosed the insert and select into a transaction

The following is what I did
________________________________________________________________


' Add the input parameter and set its properties.
Dim parameter As New Data.SqlClient.SqlParameter("pk", Data.SqlDbType.BigInt)
parameter.Direction = Data.ParameterDirection.Output
cmd.Parameters.Add(parameter)

'set insertSql to somthing u do
cmd.CommandText = "begin transaction" & vbCrLf & insertSql & vbCrLf & "select @pk =cast(scope_identity() as int);" & vbCrLf & "commit transaction"
'added try block 7/10/08
Try

Dim msg = cmd.ExecuteNonQuery()
If Val(msg) = 1 Then
'parameter.Value returns the insert identity
msg = parameter.Value
End If
Catch
'output error
End Try

_____________________________________________________________________________