2009/02/22

TextBox accepts only numbers


<asp:TextBox " runat="server" id="txt1" onkeypress="return isNumberKey(event)" />

This is the javascript method that will be called by the textbox on onkeyPress event
<SCRIPT type="text/javascript" language=Javascript>

<!--
function isNumberKey(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}
//-->
</SCRIPT>

2009/02/14

Get SelectedValue from sharepoint lookup Field


<SharePoint:FormField runat="server" id="ff30{$Pos}" ControlMode="New" FieldName="_x0627__x0644__x0628__x0646__x06" __designer:bind="{ddwrt:DataBind('i',concat('ff30',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@_x0627__x0644__x0628__x0646__x06')}" />

<SharePoint:FieldDescription runat="server" id="ff30description{$Pos}" FieldName="_x0627__x0644__x0628__x0646__x06" ControlMode="New"/>

To get the selectedvalue from sharepoint lookup field you follow these steps.

first you need to assign event onchange to this field.


<script type="text/javascript" language="javascript">
//Select the method that will run at the sharepoint page body load

_spBodyOnLoadFunctionNames.push('setEvent');

//set event function
function setEvent()
{
var selectBank= document.getElementById('ctl00_m_g_8f64049a_17a6_4a6d_89a3_c227374a7f7a_ff30_1_ctl00_Lookup');

//eventName and method that will call
selectBank.setAttribute('onchange',checkBank);


}

//function will call when event is fired
function checkBank()
{
var selectBank= document.getElementById('ctl00_m_g_8f64049a_17a6_4a6d_89a3_c227374a7f7a_ff30_1_ctl00_Lookup');
var selectedValue=selectBank.options[selectBank.selectedIndex].value;
alert(selectedValue)

}

</script>


Get SelectedValue Of dropdownlist


<script type="text/javascript" language="javascript">

var s1= document.getElementById('Select1');

var selectedValue=s1.options[s1.selectedIndex].value;

alert('selectedValue');


</script >

2009/02/08

Linking Sql Server 2005 to Oracle


This is copied article but I think it is usefull.

Oracle-SS2005 Linked ServersHere is a quick guide to setting up linked servers so you can query Oracle through Sql Server.

For my testing of this I used Sql Server Express 2005, and Oracle 9.2. This all uses simple commands that can be run via Query Analyzer or Query Tool.
First, if you've been doing this and having issues, you need to clear out any of your linked server's logins:
sp_droplinkedsrvlogin
@rmtsrvname = 'LINKED_ORA',
@locallogin = nullNext,
drop the server

EXEC sp_dropserver LINKED_ORAOk,

now let's add the linked server to Sql Server.
The linked server will be called LINKED_ORA. Once this is done you should see this listed in SS Management Studio under Server Objects->Linked Servers-- add server
EXEC sp_addlinkedserver
@server= 'LINKED_ORA',
@provider='MSDASQL',
@srvproduct='Oracle',
@datasrc= 'myOracle'
@server - this is the name to use.
It can be anything
@provider - can be either MSDASQL and MSDAORA.
Both seem to both work fine. There is talk of another provider from Oracle, but I have not gotten this one to work.
@srvproduct - must be "Oracle". I do not know why this matters
@datasrc - this is a DSN that you have set up using Oracle's .NET managerNow,
the Oracle system does not implicitly let Sql Server connect.

You need to add a login for this linked server to use.

-- add login - the DSN is protected by a password
EXEC sp_addlinkedsrvlogin
@rmtsrvname='LINKED_ORA',
@useself='false',
@rmtuser='oracleUserId',
@rmtpassword='oraclePassword'

Once this is set, then you can test using this command:
--verify tables OK
exec sp_tables_ex
@table_server = 'LINKED_ORA',
@table_schema='MySchema'
@table_schema is optional. If not provided, you will get a list of all tables in all schemas.

This will return information about the tables in the linked server.

I use it as a basic diagnostic to verify that the linked server is working. if it's not, then I use the scripts above to delete the login and linked server, then re-create using other inputs.

Now, the big pain with Oracle is that you cannot just query into the database.

I know, it is ridiculous, but I found that only OPENQUERY works.
Here is how it looks:

SELECT * FROM OPENQUERY( LINKED_ORA, 'SELECT * FROM Exp.Proj')

But from there you can now do handy things in Sql Server. One of my favorites is to re-create the Oracle schema in a Sql Server database, then use INSERT to pull in all of the Oracle data. Then you can just work with Sql Server!

Getting Vlaue of UserField In Sharepoint using JavaScript


If you need to get the value of userFiled control using javascript.

<SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="_x0627__x0644__x0631__x0642__x06" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@_x0627__x0644__x0631__x0642__x06')}"/>



<SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="_x0627__x0644__x0631__x0642__x06" ControlMode="New"/>



you can search for this ID in viewsource you can find many controls one of these controls is Span it's ID will be in my case



"ctl00_m_g_271a3a52_3741_466d_80b4_eb05da86cc05_ff2_1_ctl00_ctl00_UserField"



you can use the following code to preview the value of the control



<script type="text/javascript" language="javascript">

function CheckUser()

{

var selectedUser= document.getElementById('ctl00_m_g_271a3a52_3741_466d_80b4_eb05da86cc05_ff2_1_ctl00_ctl00_UserField').innerText; alert(selectedUser); return false;

}

</script>




This control contains the value of this field

It will breview the following value
then you can use this value in filteration or any other Issue





2009/02/07

SharePoint Built-in JS Functions


//Get Current User ID
_spUserIdex:
alert(_spUserId);

//Run JS Function on Page Load
_spBodyOnLoadFunctionNames.push(' FunctionName ');

//First we must call the EnsureSetup method
JSRequest.EnsureSetup();

//Get a query string parameter called ItemId. i.e - "page.aspx?ItemId=11" will return 11
itemId = JSRequest.QueryString["ItemId"];

//Get the current page name. i.e - "default.aspx"
itemId = JSRequest.FileName;

//Get the current path name. i.e - "/doclib/default.aspx"
itemId = JSRequest.PathName;

2009/02/02

Change SharePoint Page Title


Add the follwing content place holder in the top of your code if not exist
< asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">

<?xml:namespace prefix = asp /><asp:content contentplaceholderid="PlaceHolderPageTitle" runat="server">Add Title here</asp:content>

</asp:Content >

You can get title dynamic by adding any of this tags into "PlaceHolderPageTitle"

<sharepoint:listproperty runat="server" property="Title">
< SharePoint:ListProperty Property="Title" runat="server"/> <sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
<sharepoint:listitemproperty runat="server" property="Title">
<SharePoint:ListItemProperty Property="Title" runat="server"/>
<SharePoint:ProjectProperty Property="Title" runat="server"/>
<SharePoint:ListFormPageTitle runat="server"/>

<sharepoint:projectproperty runat="server" property="Title">

<sharepoint:listformpagetitle runat="server">


</sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listproperty>
<?xml:namespace prefix = sharepoint />
<sharepoint:listproperty runat="server" property="Title">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
</sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listproperty>
<sharepoint:listproperty runat="server" property="Title">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
</sharepoint:listformpagetitle></sharepoint:projectproperty></sharepoint:listitemproperty>
</sharepoint:listproperty><sharepoint:listproperty runat="server" property="Title">
<sharepoint:listitemproperty runat="server" property="Title">
<sharepoint:projectproperty runat="server" property="Title">
<sharepoint:listformpagetitle runat="server">
</sharepoint:listformpagetitle></sharepoint:projectproperty>
</sharepoint:listitemproperty>
</sharepoint:listproperty></sharepoint:listformpagetitle>
</sharepoint:projectproperty>
</sharepoint:listitemproperty>