Putting A Function In Class Instead Of Code Behind?

Jan 7, 2011

I have a function in a code behind file that's used to respond to a gridview event:

protected void GridviewEval(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell cell in e.Row.Cells)
{
if (cell.Text == "0") { cell.Text = "-"; }
}
}
}
It's currently in the code behind of a page and I'll be using it in other other pages.I would like to use the same code in other pages.When I cut and paste the function into a class,it's not working.

View 2 Replies


Similar Messages:

Security :: Not Extending MembershipProvider Class And Putting All This Methods In Some Unique Class And Call Its Methods Then?

Sep 16, 2010

I am beginner in web applications development. I started one little project and host it on source forge "https://homoco.svn.sourceforge.net/svnroot/homoco". And I started implementing authentication in this application to learn how it works. From my experience people never use out of the box things so I want to implement this stuff alone (like in real world projects). So some questions:

1) Is there any reason to use membership out of the box? To use database table schema, stored procedures etc. that tool generate for developer. I think that this lower control over code and I decided to implement it my self. I don't know if I am right.

2) Is my approach in this demo project good or bad (if someone have time I like to do just a little code review)? I created database based on business rules. Not using database schema that membership provider require. Extend "MembershipProvider" class to satisfy my needs. Implement queries to database myself.

3) Now, this question is a little wired but I have to ask it. If we make custom Membership Provider and do sql queries alone, implement all MembershipProvider class methods ourselves, and in application use Membership.blabla() why is this approach different from not extending MembershipProvider class and putting all this methods in some unique class and call its methods then? I hope that someone understand what I ask here.

I am sorry for three questions, but I really trying to find the best way to implement this feature in my demo project like it is a real world application.

View 3 Replies

Web Forms :: How To Add Class And Initialize Js Function In Nested / Derived Master Page's Code Behind

Feb 22, 2011

I want to add a class and initialize a JS funcion behind my nested masterpage which is being dervised from an other master page. But when I add the following code in the PageLoade event in the code behined of my derived page then it give the folowing error

Exception Details:

System.NullReferenceException: Object reference not set to an instance of an object.

CODE-

[Code]....

[Code]....

[Code]....

View 3 Replies

Web Forms :: Putting Email Class In App_Code

Dec 6, 2010

I'm trying to set up a smart way to handle email in my ASP.NET Web Application Project. I created a class in my App_Code folder named "MailHelper.cs" but am having trouble invoking it in the code-behind pages. Can someone please correct me on the correct way to do this?Here's the Mail.Helper.cs file in App_Code:

[Code]....

How do I invoke this when I'm ready to fire off a message? Let's say I have a Submit_Click event and want an email to be generated:

[Code]....

View 3 Replies

C# - Putting Tooltips Programmatically On ListBox Class?

Mar 15, 2011

I have created an asp:listbox and in the cs file, I am trying to bind it to a datasource. However, I want to put in tooltips for each option so that when you hover over a multiple-listbox you will see the name of the item in both the listbox and the tooltip.The following code is what I have tried (which obviously will not work), which will just put a big tooltip for the "select" html tag, instead of the "option" tags individually.I think I need a loop, but I'm not sure how to add attributes to each element and the ASP documentation is no help. I bet it's an easy solution, but I can't figure out how to do it.

LBRangeOfUsers.DataSource = GetSource();
LBRangeOfUsers.DataValueField = "id";
LBRangeOfUsers.DataTextField = "desc";

[code]...

View 2 Replies

Code For Putting And Removing Breakpoint After Some Time In C#?

Mar 18, 2011

Code for putting and removing breakpoint after some time in asp.net?

View 1 Replies

C# - List <Class> New Class Takes Up Memory - Can Set C=null; In The Code

Jul 23, 2010

List New Class takes up memory?Do I need C=null; in the code below?

//class Category
public List<Category> SelectAll()
{
List<Category> LV = new List<Category>();
string command = "SELECT * from categories";
SqlCommand sc = new SqlCommand(command, new SqlConnection(GlobalFunction.Function.GetConnectionString()));
sc.Connection.Open();
SqlDataReader dr = sc.ExecuteReader();
using(dr)
{
[code]...

View 5 Replies

Code Reusability / Put The Code In One Class And Want To Inherit Same Code In Each Page?

Apr 12, 2010

Following is the code to insert userName from session and PageName into table to keep record that how many times a user does hit a particular page.

To avoid repitition of code I want to put the code in one class and want to inherit same code in each page.

How to get this task? Please do share with me? Here is the OK code:

[Code]....

View 17 Replies

How To Access Label In Parent Class Of Code Behind Class

May 24, 2010

I have a class (name PageBase) that is inhariting System .Web.UI .Page and all my .aspx page behind classes are inhariting this class. This way I have put some common things in PageBase class.

For showing errors I want to put showMessage funtion in PageBase as well so that I may have not put it in every page and it will easy to manage this way.

Probem is that how PageBase class will access a control which is in aspx page in its child class (child class of PageBase) .

I dont want to pass control as argument to function in parent class, is ther any other way ?

View 7 Replies

Web Forms :: Call A Code Behind Function Form Html Source Code?

Mar 3, 2010

I want to call a function present in code behind from front page (html : source code)

i want to use like this:

Source code

<a href='<%# linkAlpha("B").ToString()) %>' title="B" id="B_List" runat = "server">B</a>

Code Behind

protected string linkAlpha(string value)
{
// /market-research/<%#Eval("customname")%>/
string str = "";
if (Request.Url.DnsSafeHost == "localhost")
{ // /market-reports/<%# Eval("customname")%>/
str = "Alpha_Category.aspx?q=" + value.ToString().Trim();
// Response.Redirect("Alpha_Category.aspx?q=" + value.ToString().Trim());
}
else
{
// str = "/market-reports/" + value.ToString().Trim() + "/";
str = "/Alpha_Category.aspx?q=" + value.ToString().Trim();
}
return str;
}

View 2 Replies

Call Javascript Function From Code Behind After Server Side Code Executes

May 25, 2010

I have an asp.net button, that when clicked calls a code behind function. The function does some evaluation, and then I want to call javascript from within this asp.net function.

View 2 Replies

Web Forms :: Div Onclick Fire Function(on Code-behind Code) With ASP

Jul 2, 2010

div onclick fire function(on code-behind code) with ASP

[Code]....

View 3 Replies

Calling Function From VB.Net Class?

Mar 11, 2011

Just wondering how I do this, Im creating a class that will have my common database functions. So for example I've created a function db_con in a class called db_functions.How do i use that db_con function in for example my homepage vb code?Do I import the class? I've tried typing the full class and method name, no joy so far?

View 1 Replies

Refer Shared Function In Its Own Class?

Mar 2, 2010

how to refer shared function in a class , this function itself inside same class

public class cls1

Public Shared Function getDBDate(ByVal pDate As Date) As String
Return Format(pDate, "yyyy-MM-dd")
End Function

Private Function GetDb_Format(ByVal pDateString) As String
Dim d As Date = Me.ParseDate(pDateString)
Return clsDate.getDBDate(d)

End Function

End Class

can i have any other way to use getDbDate function

View 2 Replies

C# - Add Function To Built-in Class Using Inheritance?

Mar 21, 2010

I'm trying to add a IsImage property that I wrote myself to the HttpPostedFile class, so that if a user is uploading a file, I can do something like this:FileUpload1.PostedFile.IsImageHow can I do that in C#?

View 1 Replies

Architecture :: What Is The Function Of Abstract Class

Oct 24, 2010

what is the function of abstract class, why design pattern need to build BLL and DAL

anyone give an example for my reference as I am getting strat to build my web-based project

View 3 Replies

MVC :: Access A Class Function From A View?

Feb 23, 2010

I have in my Models folder a Class named "Utilities".

I need to acces one method of that class inside a view, like <%if(IsASelectedCategory(item.categoryId, item.productId))%>

View 1 Replies

Accessing A Class Properties In Function?

Apr 15, 2010

I am unsure of how to reference the properties of my class in a function. Here is how I see it in my head, but how do i go about this?

WebService.vb

[Code]....

UserClasses.vb

[Code]....

View 4 Replies

Web Forms :: How To Write A Function To Return A CSS Class Name

Jan 24, 2010

I'm new to C# and ASP and can't seem to figure out how to write a function to return a CSS Class name.

Here's what I have so far:

In "MyWeb.master" I have a line that reads:

<asp:HyperLink ID="HyperLink1" text="xxxxx"
cssClass='<%# MyCssStyle("ddd") %>'
NavigateUrl="http://www.RDRR.com/Catalog.aspx?TribeID=1"
runat="server" />

And in "MyWeb.master.cs" I have a routine within the partial class that reads:

public string MyCssStyle(string myInput)
{
myInput = "NavigationBarUnselected";
return myInput;
}

This code does not throw an error, but neither does it return a value. What have I missed?

View 8 Replies

How To Set Datasource Gridview To Linq In A Class Function

Aug 4, 2010

i have my page who load my gridview as: GRW.datasource=className.List2(2);i have this function in my class

[Code]....

it returns an error , cannot convert single result to queryable!! in " blo= DB.MarketList(TypeID);"

View 10 Replies

Security :: Add Delete Function To 2nd Class File?

Jan 7, 2011

We are using ASP security on the site, i found months back a tutorial on implementing a pretty simple management page that allows you to create, edit, delete and add roles as well as adding users to roles from 1 page..

It has been working fine, but we added our own security matrix to the site, everything that has to do with the ASP side of the security works as expected and no issues or concerns.. but with our matrix in place, i need to tie the 2 together for 1 thing.. the deleting of a user..

The delete function works great.. but i would like to add my delete to that function so that the users security matrix is deleted as well when their account is done.

Within the class that is handling all the membership functionality, there is this portion tha handles the deleting, i would like to add a call to my class that has the delete method so that when you click delete, the membership account as well as the matrix record is deleted. Since the delete is already setup within my 2nd class, how can i call it to execute it from within the first class?

[Code]....

View 3 Replies

C# - Reference An ASP Control Inside A Function Or Class Method?

Oct 7, 2010

How do you reference an asp.net control on your page inside a function or a class.
private void PageLoad(object sender, EventArgs e)
{
//An example control from my page is txtUserName
ChangeText(ref txtUserName, "Hello World");
}
private void ChangeText(ref HtmlGenericControl control, string text)
{
control.InnerText = text;
}
Will this actually change the text of the txtUserName control?
I tried this and is working
private void PageLoad(object sender, EventArgs e)
{
ChangeText(txtUserName, "Hello World");
}
private void ChangeText(TextBox control, string text)
{
control.Text = text;
}

View 2 Replies

Make Asynchronous Call In Static Class Function?

May 17, 2010

is it possible to make an asynchronous call to a static class function?

View 3 Replies

Function To Send An Entire Class To A Store Procedure?

Jul 13, 2010

I have been working a in a function to send all the properties of a class to a store procedure in any DB. I made it work when i define the specific class in the declaration of the function like this:

protected Boolean LoadDataDB(Class1 objClass1,Type t,String StoreProc)

But what i want is to make this function as generic as posible. I thought on replace the "Class1 objClass1" part with something like "object obj" but it didn't work. If Ipull this of, it will be very usefull for me. Up next i'm copying what i have so far.

[Code]....

The error appears in the wrap.AddInParameter line, in the following code:

objeto[Prop.Name.ToString()]

And it says something like "Can not apply indexing with [] to an expression of type object"

View 2 Replies

VS 2010 - Passing Image Control To Function In A Class?

Oct 31, 2012

I wrote a function in code behind of the aspx file to get from an SQL database the imageurl and assign it to that image's URL. This works fine so I decided to move it to a class but now the imageurl does not exist because the passed image control is now refering to system.drawing.image not the web image.

Code:
Public Sub ShowCodeImages(sProdCode As String, ByRef imgCode As Control, sConnectionString As String)

Dim sSQL As String
Dim sqlDCStock As New SqlConnection
Dim sqlDAStock As SqlDataAdapter
Dim sqlDTStock As DataTable

[Code] .....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved