Web Forms :: How To Write A Code In Class File
Aug 2, 2013
I have a code which saves the control id and its text in database..(and it is working fine).This code is written in default.aspx.cs which will save all the controls(of deault.aspx) id and name in database.I want to make a class file and then call this class file in page rather than writing the code in page because there will be multiple pages where this can be called.write this function DisplyDetails() in class file..code is as below..
public partial class _Default : System.Web.UI.Page
{
string controlId, propertyValue,other;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["abc"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
[code]...
View 1 Replies
Similar Messages:
Dec 22, 2010
I'm having problems drawing the lines on what code goes where in the following case. What goes in the View, Controller and Model. It should be noted that this is my first MVC project.So I'm building a bilingual site where the user may select either English or Norwegian language. I want the user to be able to choose language with a link at the top of the page. The link for the selected language at any time is emphasized with a certain CSS class.
The user setting with the selected language at any time is stored in a cookie at the client. When a request is done, the cookie is parsed and the settings are objectified as a part of the Model the way I've implemented it as of now (please object if you find this weird, but this is not the main focus of this post). I.e. a super-class which all my models inherit from, has the UserSettings class with the Language property.Now, where do I write the code which translates the language property into a CSS class?Option A, the View: I envision some code which interprets the language and output one of two possible lines of code based on this. We'll have IF's in the View.
Option B, the Controller: Logic in the Action method sets a ViewData-property with the name of the CSS class for both the link to the Norwegian and the English language.
Option C, the Model: I create a new property in the Model doing the same thing as the code in Option B. Except now I get strongly-typed parameters in the View and intellisense. (But I do suspect you guys will not like this solution for separation-of-concerns-reasons)
Option D, the ViewModel* I create a new class which is a ViewModel for the Model with the same property as in Option C. Now I get better separation of concerns.Yes I know there's no ViewModel in MVC, but I also know some people implement it anyway.
So what do you say? A,B,C or D? Or maybe you've got an E?
View 3 Replies
Jan 10, 2010
how do i write a async class like WebClient? Is there anyway i can keep it short and does not have to repeat it for every method?
for example, i have:
Download(string a)
Download(string a, string b)
do i have to rewrite Async + Complete method for each of these?
View 4 Replies
Feb 10, 2011
I have web page, in that I place some links(hyperlinks or linkbuttons).
each button, when user clicks then a file should be downloaded to the user system..
files that are to be downloaded exists in asp.net website project folder>>downloads folder.
View 1 Replies
Feb 6, 2010
i have store the file information like name and size in the datagrid not the content when i click the view button in the grid how to display file contents
View 4 Replies
Dec 21, 2010
there are an access file . >> "test_file.mdb"
there are a table in mdb file .>> "test_table1"
and there are 2 columns in "test_table1" >> "name" and "age"
and i have 2 textbox in my web form . >> "textbox_name" and "textbox_age"
and i have a button for save textbox_name.text and textbox_age.text in mdb file .
i need adox vb code for save textboxs data in mdb file .
View 4 Replies
Aug 28, 2010
If Not IsDBNull(ext) Then
ext = LCase(ext)
End If
Select Case ext
'Case ".htm", ".html"
' type = "text/HTML"
'Case ".txt"
' type = "text/plain"
'Case ".doc", ".rtf"
' type = "Application/msword"
'Case ".csv", ".xls"
' type = "Application/x-msexcel"........................
View 5 Replies
Apr 2, 2010
I was wondering which of these two is better from the aspect of performance.
I was thinking that possibly Class files stored in App_Code works faster because they are sort of pre-compiled but i am not 100% sure.
Specifically i am overriding onInit event on each page using some functions that i am not certain where to place.
Not that i complaint on the speed but i want to be sure that i am doing the right thing.
View 7 Replies
Jul 17, 2010
For some time now I am trying to figure out how I can refactor some of my code to reduce redundancy throughout my application. I am just learning the basics of OOP and can create simple classes and methods but my knowledge is limited in terms of practical applicability. The following bit of code illustrates my frustration:
[Code]....
This bit of code is used on several pages of my project in the pages codebehind file. How can I move this to a class file. I don't know how to reference an object like a gridview in a class because it does not exist like it does on the actual page.
View 2 Replies
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
Mar 11, 2011
i want to nkow ik i can write a html code in the code behind if yes show me how?
View 3 Replies
Oct 7, 2010
I want to create and write file in "C:windowssystem32" this path.some computer give the error access denied.i want some code in C# who give the permission to folder.
View 5 Replies
Jan 16, 2010
i have code in .cs class file
i need it in .vb
i used conversion tool for converting
but i feel its not proper as i am not able to reference it in my page
is there any other way
View 4 Replies
Nov 18, 2010
I have build a UserControl with separate code behind file.In that code behind file i have defined some public properties in the Partial class of user control that was automatically generated.Those properties will initialize some properties of controls that are used in the control.Now, in .aspx page i used this User Control and initialized the public properties through code behind of aspx page for dynamic contents.
View 6 Replies
Apr 19, 2010
can you give some information about how to write a class that return mor than one value
for ex. i want to create a class getSettings("UserName") that return the language and theme for that user.
View 2 Replies
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
Jan 10, 2010
How can I write this with a masterpage
View 2 Replies
Nov 10, 2010
i want to use a link button in default.aspx.cs....
how i can write this and put that in a Literal?
View 3 Replies
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
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
Sep 16, 2010
one particular area the image should scroll for every 45 sec's
View 2 Replies
May 10, 2010
I have a panel which displays data on selected criteris with the followin columns Confirmationnumber fromdate todate propertynumber now the data which is in the confirmation number is a hyperlink which when clicked should be directed to the page with that particular confirmation number and similarly the property number is a hyperlink which should be directed to that property number page when clicked I dont know how to give the link to it
[code]...
<td><a href="/?ID=Booking.View&BookingID=<%#Eval("ReservationID")%>"><%#Eval("BookingConfirmationCode")%></a></td>
The above code is working so how I present this bold line in the above criteria
View 49 Replies
Dec 14, 2010
how to write text in asp.panel in code behind
[Code]....
View 1 Replies
Feb 25, 2011
i want to write a code in vb when a button is clicked is should search the three different radio buttons and display the data if it matches to input user data ..
View 4 Replies
Oct 19, 2013
How to use C# code in .aspx page?
means in designing page....
View 1 Replies