.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Can I write Functions can be called from every page?

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net


I have some functions which will be call in some pages. I don't want to define the same functions in every page as it will be hard if I need change the code.

I've already use a class to hold the common functions and use that class in the page if I need those function.

But the problem is:

Some methods in the aspx.cs page are not available in the .cs class. Such as "Session", "Responce.Redirect","Page".

Let's say I have a function which check the session value and redirect the user. 

                string pId = Session["ProjectID"] as string ;
                if (pId != null)

These codes get error in the .cs class but only work in aspx.cs page.

I don't know which namespace should be used in the .cs class.

Is there a way I can write this function in one place and call it in the page?

Thanks and I hope I've stated the problem clear.

View Complete Post

More Related Resource Links

Can I write a wcf endpoint to communicate with JSON from Jquery on page?

Hi Guys,I need to be able to expose information to a page, and I need to write the information in xml on my webserver which will be dynamically created from the database. I need to use json to pass the data from the screen back to the server two way communication xms back and forth. Is it actually any good using a wcf endpoint to serve the json back to the page and use query with wcf? Is this possible?Or is it easier to use standard pages .aspx and just do a call to a url and get the json with jquery....We will probably want to send this information to other locations at some point in the future too....Cheers,Pete

Google Checkout Notification Page Not called

Hi All, I am implementing Google checkout in asp.net website. I done with all the checkout stuff. But I stuck in Notification page handler. My Notification aspx page is not get called. In sanbox integration console its showing 401 unauthorized access error. I tried many things but not succeeded yet. Can anyone help me to sort out this issue. Please don't refer google checkout page because I already spend lots of time on it to sort out this issue. Thanks in Advance Micky

Where to write the code for mail in master page

below is my code. please anyone tell me where to write vbscript to send email after validating the fields<%@ Page Language="VB" MasterPageFile="~/Master.master" AutoEventWireup="false" CodeFile="Enquiry.aspx.vb" Inherits="Enquiry" title="Enquiry - MTM Active" %><asp:Content ID="Content1" ContentPlaceHolderID="ConPage" Runat="Server"><script type="text/javascript" src="Js/Blank.js"></script><script type ="text/javascript">function CmdSubmit_onclick(){if (fnValidate()==true)return true;else return false;}function fnValidate() {if(IsBlank(" Name",document.getElementById ("TxtName").value)==false)        {            document.getElementById ("TxtName").focus();            return false;         }        if(IsBlank(" Email",document.getElementById ("TxtEmailID").value)==false)        {            document.getElementById ("TxtEmailID").focus();            return false;    &n

Page.IsValid cannot be called before validation has taken place

This is my first asp.net application and it looks like I am in a rock and a hard place.  I have a multi page formview and I want to allow the user to page back with causing validation, but if I don't cause validation on the page back button, I get an error  Page.IsValid cannot be called before validation has taken place. It should be queried in the event handler for a control that has CausesValidation=True and initiated the postback, or after a call to Page.Validate.Source Error:  Line 41: Line 42:     Protected Sub FormView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewPageEventArgs) Handles FormView1.PageIndexChangingLine 43:         FormView1.UpdateItem(True)Line 44:         If FormView1.PageIndex < 1 ThenLine 45:             FormView1.FindControl("ImpactsTextBox").Focus() Line 43 in the vb file allows me to update an item.   How do I get around this problem?  Is this where I need a "if not postback"?  Any examples would be appreciated.  

Can i not show Response.write on a page?



I'm doing something for  paypal.

So i have my values for paypal PDT like this:

 Public Function PayPalPostForm() As String
        Dim s = Request.QueryString("tx")
        Dim PostUrl As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
        Dim Cmd As String = "_notify-synch"
        Dim Method As String = "post"
        Dim submitvalue As String = "PDT"
        Dim tx As String = s
        'my sandbox merchand identity token 
        Dim at As String = "J9Z11-6776aOBoIOMqiWDEFGUmonSwyqM2QiGriz7Rn-f7Y_z0KEQkUvLSa"

        'Create the Form to write to the page with PayPal parameters      
        Dim ppForm As New StringBuilder()
        ppForm.AppendFormat("<Form name='frmPP' id='frmPP' action='{0}' method='{1}'>", PostUrl, Method)        
        ppForm.AppendFormat("<input type='hidden' name='cmd' value='{0}'>", Cmd)
        ppForm.AppendFormat("<input type='hidden' name='tx' value='{0}'>", tx)
        Return ppForm.ToString()
    End Function

and then i will send the form to paypal and ge

write common functions in C# project

I want to create  one database application. Where should I write the connect to database fuction so that I would be able to access the database through other forms.

Response.Redirect cannot be called in a page callback error message.


Hi.  I'm using the Dundas Chart Controls in VS 2005.  These controls are built utilizing AJAX.  I have a basic page with a dundas chart control containing a funnel chart.  The funnel contains Quotes, Sales Orders and Invoices.  When the user clicks on the control, I want to determine whether they clicked on Quotes, Sales Orders or Invoices and transfer to the appropriate Details Page.  I've got the code working to determine which transaction type they clicked on; but, I get the "Response.Redirect cannot be called in a page callback." error when the page tries to redirect.  Note: I get a similar issue if I try server.transfer.


 Here's my code:

Dim hitTestResult As Dundas.Charting.WebControl.HitTestResult = Chart1.HitTest(e.X, e.Y)

            If Not (hitTestResult Is Nothing) Then

                Dim clicked As Dundas.Charting.WebControl.DataPoint = hitTestResult.Series.Points(hitTestResult.PointIndex)

                Select Case hitTestResult.PointIndex
                    Case 0


how to trigger separate client-side functions on completion of different Updatepanels on same page



I have one updatepanel1 on my page and i trigger a javascript function on completion using the function below:


Now I have to add one more - udpatepanel2 in the same page, for which a different javascript function has to be triggered on completion..

Is it possible? Please share your ideas...

Best way to "ensure" that an ASMX web service is only called from AJAX on a specific ASPX page


I have an ASPX page which hosts a Custom Control.  That custom control needs to call an ASMX web service.  I would use a PageMethod, if the fact that I'm calling from within a Custom Control didn't preclude that. 

I'm looking for some guidance on the most effective way to try and lock down the ASMX call such that it will only succeed for my users calling it from my ASPX page - and not for anyone trying to call it from elsewhere.  I've seen various ideas around session variables and so on.

What's the expert view, please?

Interop problem: VB6 COM code functions incorrectly when called from .net code.


I have found recently with some machines or some user accounts that calling some VB6 code from .Net fails to execute properly.
I have two examples:

  1. I have this simple VB6 dll, called by VB.Net code, that calls another simple VB6 dll using createobject.  The second object displays a form modally with progress bars, runs queries against a SQL server database to create and fill a table, and then closes (unload) that progress form and returns the table name.  The first object then takes this data to do additional processing on the SQL server and returns a SELECT statement to the object that called it. 
    For most people this works correctly, however for two users on a terminal server it fails to run correctly.  What it does is not close the form, however all of the updates to the database in both dlls are run according to SQL profiler.  The .Net process that called it never seems to get a return value from the COM dll for those 2 users only.  I even tried to recreate the user's profile, but it did not help.  Note that the .Net code calls the first VB6 dll using CreateObject as well.
    The strangest thing about this is what occurred when I added MsgBox calls to try to determine what was wrong with the progress form.  I added one immediately after the form's status bas was updated to "Finished

How to freeze the background page when modal popup window called



when i call modal popup extender the background is scrolling , i want to freeze the background page then
 is there any properties or any other idea to get this .. 

jquery and javascript page load events and functions


Hello friends,

m studying the jquery and js these days, i notice lot of the functions that triggerd the js and jquery at page load.....

like some exampoles are.......

1. jQuery(function($){});

2. <body onload="initialize();>

3. $(document).ready(function(){});

4. function pageLoad(){}

5. and many more....

my question is that many of the functions inside that are not work at another type of page load trigger function....

and some of the page load event also makes conflict with each other.......

so i need to know is that what is the mean of all that event when they use?

thanks and regards

inderjeet singh khalsa

Changing the graphics on the home page of a SharePoint site

When you create a site in Microsoft Windows SharePoint Services by using the default Team Site template, the home page includes two default graphics. A Windows SharePoint Services graphic appears in the body of the page, and a picture of a house in a circle appears near the site title. You can change these graphics to customize your site. Changing the smaller graphic requires a Windows SharePoint Services compatible Web page editor

Using jQuery to directly call ASP.NET AJAX page methods

Here I am looking to explain how to call page methods using jQuery. Using jQuery to directly call ASP.NET AJAX page methods

Insert value using Table Value Functions

a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.

Introduction to Functions

A function is a section of code that is used to perform an isolated assignment. Once it has performed its assignment, the function can be accessed to present its result(s).

In Transact-SQL, a function is considered an object. After creating the function object, it becomes part of a database. You can then execute it when necessary.

Built-In Functions Fundamentals

While your primary job as a database developer consists of creating lists, probably your second most important job is to assist your users with the various assignments they must perform on your application. One way you can assist is to use functions that perform otherwise complex tasks. We introduced and described functions in the previous lesson. To assist your development with the different tasks of a database, Transact-SQL ships with various already created and tested functions. You just need to be aware of these functions, their syntax, and the results they produce.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend