global function/sub function page

Hi

I want to know how i can create a page with globol functions that is to be included every page of the site. Does anyone know how to do this or know of any tutorials - hopefully in asp 1x and in vb

 

thanks in advance

Hesh

0
orangelightblub
8/6/2007 11:11:35 AM
asp.net.visual-basic.net 3721 articles. 0 followers. Follow

5 Replies
623 Views

Similar Articles

[PageSpeed] 30

for Global Function ....

what you can do is .. develop a class with Static/Shared Methods.. and that would be accessible through out the application pages...

here is an example

 

C# 

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Mail;

namespace RealEstate.Common
{
public class CommonFunctions
{

/// <summary>
/// handles null or blank values for string type
/// </summary>
/// <param name="argStr">string value to handle</param>
/// <returns>returns string</returns>
public static string NullString(string argStr)
{
string strReturnString = "";
if (argStr.Equals(DBNull.Value))
strReturnString = "";
else if (Convert.ToString(argStr) == "")
strReturnString = "";
else if (Convert.ToString(argStr) == "&nbsp;")
strReturnString = "";
else strReturnString = Convert.ToString(argStr); return strReturnString;
}

public static Double NullValue(Double argDbl)
{
Double dblReturnDouble = 0.0;
if (argDbl.Equals(DBNull.Value))
dblReturnDouble = 0.0;
else if (Convert.ToString(argDbl) == "")
dblReturnDouble = 0.0;
else if (Convert.ToString(argDbl) == "&nbsp;")
dblReturnDouble = 0.0;
else dblReturnDouble = Convert.ToDouble(argDbl); return dblReturnDouble;
}

public static bool SendMail(string strFrom, string strTo, string strSubject, string strMsg)
{
try { // Create the mail message MailMessage objMailMsg = new MailMessage(strFrom, strTo);

objMailMsg.BodyEncoding = Encoding.UTF8;
objMailMsg.Subject = strSubject;
objMailMsg.Body = strMsg;
objMailMsg.Priority = MailPriority.High;
objMailMsg.IsBodyHtml = true;

//prepare to send mail via SMTP transport SmtpClient objSMTPClient = new SmtpClient();
objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
objSMTPClient.Send(objMailMsg);
return true;
}
catch (Exception ex)
{
throw ex;
}
}
}
}

  

 

 VB#

 

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Net
Imports System.Net.Mail

Namespace RealEstate.Common
Public Class CommonFunctions

''' <summary>
''' handles null or blank values for string type
''' </summary>
''' <param name="argStr">string value to handle</param>
''' <returns>returns string</returns>
Public Shared Function NullString(ByVal argStr As String) As String
Dim
strReturnString As String = "" If argStr.Equals(DBNull.Value) Then strReturnString = "" ElseIf Convert.ToString(argStr) = "" Then strReturnString = "" ElseIf Convert.ToString(argStr) = "&nbsp;" Then strReturnString = "" Else strReturnString = Convert.ToString(argStr) End If

Return
strReturnString
End Function

Public Shared Function
NullValue(ByVal argDbl As Double) As Double
Dim
dblReturnDouble As Double = 0.0
If argDbl.Equals(DBNull.Value) Then dblReturnDouble = 0.0 ElseIf Convert.ToString(argDbl) = "" Then dblReturnDouble = 0.0 ElseIf Convert.ToString(argDbl) = "&nbsp;" Then dblReturnDouble = 0.0 Else dblReturnDouble = Convert.ToDouble(argDbl) End If

Return
dblReturnDouble
End Function

Public Shared Function
SendMail(ByVal strFrom As String, ByVal strTo As String, ByVal strSubject As String, ByVal strMsg As String) As Boolean
Try
' Create the mail message Dim objMailMsg As MailMessage = New MailMessage(strFrom, strTo)

objMailMsg.BodyEncoding = Encoding.UTF8
objMailMsg.Subject = strSubject
objMailMsg.Body = strMsg
objMailMsg.Priority = MailPriority.High
objMailMsg.IsBodyHtml = True 'prepare to send mail via SMTP transport Dim objSMTPClient As SmtpClient = New SmtpClient()
objSMTPClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis
objSMTPClient.Send(objMailMsg)
Return True
Catch
ex As Exception
Throw ex
End Try
End Function
End Class
End Namespace

  

hope it helps./. 


Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
8/6/2007 12:08:39 PM

Hi Thanks for the example - the other problem is how can i put the codefile into the main page - cause i already got another codefile

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="registration.aspx.vb" Inherits="admin_register_registration" debug="true"%>
<%
@ Page Language="VB" AutoEventWireup="false" CodeFile="/app_Code/commonfunc.vb" Inherits="CommonFunctions" %>

if I do this i get the page error 'There can be only one 'page' directive'

thanks
Hesh 

0
orangelightblub
8/6/2007 12:54:58 PM

 based on my understanding.. there can be only one code file per page... so you cant have more than one page directive or more than one "codefile" option in page directive.. can you tell me what you want to do exactly.., so everybody can help you..

here in second page directive,, i can see that you are trying to give CommonFunc.vb as code file to this page... is there any need to do ?... i think this class would contain common functions as name implies.. so you can simply declare all the functions in this class as shared to directly access them via class name or you can simply develop a class and use its functions via creating the object instance of this class.. hope i got your problem... let me know it i dont... Thanx


Thanx,
[KaushaL] || BloG || Profile || Microsoft MVP

"I would love to change the world, but they won’t give me the source code"


Don't forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and mark your thread as Resolved for the sake of Future Readers.
0
kaushalparik27
8/6/2007 1:10:59 PM

 

hi dear for declaration of global function you can take one module in this module you have to declare one function , ans call this function whenever you have requirement

ex:-

 Imports System.Data.SqlClient

 Module modGlbFunctions

Public Function funFillDataset(ByVal strQuery As String, ByVal sqlDadapter As SqlDataAdapter, ByVal con As SqlConnection, ByVal strTable As String, ByRef dsTemp As DataSet)

sqlDadapter = New SqlDataAdapter(strQuery, con)

sqlDadapter.Fill(dsTemp, strTable)

End Function

End Module

//you can call this function on evrerypage.

//this is very simple and easy way plz use this

with thanks  

hirdesh sharad


hirdesh sharad
0
hirdesh
8/24/2007 10:37:10 AM

orangelightblub:

Hi Thanks for the example - the other problem is how can i put the codefile into the main page - cause i already got another codefile

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="registration.aspx.vb" Inherits="admin_register_registration" debug="true"%>
<%
@ Page Language="VB" AutoEventWireup="false" CodeFile="/app_Code/commonfunc.vb" Inherits="CommonFunctions" %>

if I do this i get the page error 'There can be only one 'page' directive'

 You can try the code below.

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="registration.aspx.vb" Inherits="admin_register_registration" debug="true"%>
<%
@ Assembly Src="/app_Code/commonfunc.vb" %> 

0
tongyin
9/2/2007 1:34:39 PM
Reply:

Similar Artilces:

Visual Basic.NET or Visual Studio.NET?
OK, this has probably been asked before... I'm a student looking to cut my costs, and I can do this by just purchasing Visual Basic.NET as opposed to the fully-fledged Visual Studio.NET application. Of course, I'll only be able to program in VB, but that's fine with me. I wanted to know if all of the ASP.NET specific options are available, such as using a WYSIWYG editor? I'd also like to know if VB.NET has IntelliSense, or that's a specific option only available to Visual Studio.NET users. Thanks in advance. I'd have to believe that VB.Net has intellisense. What is the price d...

Visual Studio .Net? Visual Basic .Net?
Okay, I admit it -- I know nothing about .Net. I'm a Visual Basic and ASP developer. DotNetNuke is my first tentative step into the whole ".Net Thing", and I'm looking for some advice... What do I really need to be able to make some modifications, or new modules for DotNetNuke? Do I need the full, THOUSAND DOLLAR Visual Studio .Net 2003 package, or can I get away with the HUNDRED DOLLAR Visual Basic .Net Standard package?Chameleon Systems, Inc. You can use webmatrix, available here for free. One of the drawbacks of webmatrix however is that it does not support code-be...

Visual Basic.NET or Visual Studio.NET? #2
I am currently using the Web Matrix to develop ASP.NET applications, but I am keep to upgrade to VS.NET. However, I can't justify spending $1,000 at the moment. I then found the MUCH cheaper "Visual Basic .NET 2003 Standard Edition" which is only $100. I have very little C# knowledge, and use Basic almost all the time. Would this be a good tool to use for web development? Does it support all the code behind stuff that VS users love so much? Thanks!! I use "VB.NET Standard Edition" and I'm happy with it. It has exactly the same features as Visual Studio.NET. Th...

Visual Basic .NET 2003 vs Visual Studio .NET 2003
Hi, If im going to be coding my ASP.NET in just VB.NET then would I be able to go for the cheaper option of buying Visual Basic .NET 2003 ?? - Carl S Yes.Starting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Blog Are there any limitations if I was doing my ASP.NET with VB.NET in Visual Basic .NET 2003 than if I was using the full Visual Studio .NET 2003 ?? Or are the only advantages of Visual Studio .NET 2003 in that it supports more programming languages ?? - Carl S You should check the MS Web site, but I believe that, given an edition (Standard, Professional...

java script function in .net function
Dear All,I’m trying to open up a window with a form in it, but first I need to make sure that the user checked at least one or more item on a list with checkboxes in each row on the page where I push the button to open the window from.I use the following simple code:Public Sub btnLog_onClick(ByVal sender As System.Object, ByVal e As System.EventArgs)           Dim myCsv = getTickedItems(1)         If myCsv = "" Then             Exit Sub  ...

ADO.NET Programming in Visual Basic .NET
Has anyone read "ADO.NET Programming in Visual Basic .NET, Second Edition" by Steve Holzner (Author), Bob Howell (Author)? I am trying to working on a project and there are a few things that I need to tie up quickly in my web forms. Is this book a good one? karls------------------------------------'Old and wrinkled is not what I expected to become when I grew up!'...

Converting Visual Basic 6 to Visual Basic .NET
Hi, I found this program that would get the mac address of a computer given its IP. I converted it into vb.net and it gave 2 errors. It said that I couldn't use "any" in declarations, so I found out what variable it was tryign to pass and changed the any to that data type. Now, the program will start in vb.net... but when I click the button, it returns the wrong mac address, while the one in vb6 returned the correct one.All you have to do is add 2 textboxes to the form and 1 button, dont change their names.::::::::::VB6 CODE::::::::::Option ExplicitPrivate Const NO_ERROR = 0Private Declare F...

C# Visual Basic.NET JScript.NET what should I choose ?
I'm just a beginner with programing ASP.NET web sistes. Unfortunatelly I don't know any of the languages supported by ASP. (By the time I programmed in DELPHI and SQL) So I should start to learn one of the languages. Could somebody help me to choose the language I should use ? Which and why ? Thanks in advance, Gonzi Use C# or VB.NET, which ever you are comfortable with. Go here to see sample of both in use http://samples.gotdotnet.com/quickstart/aspplus Ultimately, once you get more advanced, you'll really want to become comfortable with both languages. I ...

Print page function in VB .net
Hi I am new in asp.net, and I am having a hard time figuring out how to print a page when clicking on a button. I know I have to use the printdocument class, but it is a bit confusing the training material on-line. Can somebody explain to me how to make such a print function on a page, and post an example??? Would really appreciate it! You need to use Javascript, because the web page is on the client with no connection to the server while the user is actually browsing the page. Here is a link to an FAQ on printing in JavaScript.Starting with ASP.NET 2.0? Look at:Programming...

Support of global functions in datawindow .net
Hi, i need any idea how to write user functions such as npos(string1, string2, n) for use in datawindow expression. In powerbuilder i wrote global functions, in datawindow.net it seems like a problem. Thanks for any idea. Unfortunately, this feature isn't supported in DataWindow.NET. On 27 Dec 2006 04:51:34 -0700, Allan Konecny wrote: >Hi, i need any idea how to write user functions such as >npos(string1, string2, n) for use in datawindow expression. >In powerbuilder i wrote global functions, in datawindow.net >it seems like a problem. Thanks for any idea. Globa...

__doPostBack function in .NET 1.x and .NET 2.0
It appears that the __doPostBack function has changed in .NET 2.0. The .NET 2.0 version doesn't seem to handle the conversion of dollar signs ("$") in generate control names to colons (":"). I'm using an Axezz datagrid inside of a MasterPage along with 3 other user controls in the MasterPage. The Axezz datagrid has sorting capablilites. When sorting is enabled the column have script attached to them that reads "javascript:__doPostBack('_ctl0$ContentPlaceHolder1$Grid1','orderby:5:1')" when the grid is rendered. The problem is that when I click on the column, the page post back, but the g...

Function functionality ?
Hello, I have a Function : create Function F1 ........ as update T1 set col1=col1+1; commit; return col1; end; Lets say col1 value before the func. is called is 100. Now, if user1 executes this function and user2 also executes the same function, at the same time. 1) What value is returned for user1 and user2. Would that update stt. locks the table, and allows only 1 user to access it? 2) My requiemnent is that the 2 users should get different values from the function. thanks for your help -Sravan Sravan wrote... > Hello, > I have a F...

Global functions vs global userobject functions
Working with PB 7, I often ask myself what is the good way. My applications has one global instance of a userobject u_function and use also global functions. In some case, the choice of where to put a new function is evident. When I could need the function in dw expression, there are global, when I need to call functions with different parameters, they are userobject functions. But, the other functions ? Where is the best place for them ? Global or in the userobject ? I thnik u can go for Global functions Since u have in need in DW expression also. I think Overload wi...

Can I go from VS .NET 2003 to Visual Basic .NET 2003?
Hi, I just developed a commercial application using the trial version of Visual Studio .NET 2003.  My trial is about to expire.  I was hoping .NET 2.0 would be released by now, but that is obviously months away so I'm wondering if I could save a few hundred bucks by buying Visual Basic .NET 2003(around $110 i think) instead of having to buy Visual Studio .NET 2003, which I believe is up around $600 or so.   All my code is Visual Basic, so that's why I'm thinking that's all I need.  And it's mostly web development that I do if that matters.  T...

Web resources about - global function/sub function page - asp.net.visual-basic.net

Resources last updated: 12/4/2015 2:44:18 AM