Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP:NET
hi guys,
 
i have a masterpage.master and default.aspx. i was creating some function in class file .cs i want to call it in master page how can i do this? i am newe in this? pls help me out..
 
thnx in advance
Posted 21-Jan-13 9:06am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The master page can't directly call functions in the child class - it may not exist!
It's similar to the situation when you derive a C# class from a base class. The base class does not know what classes will be derived from it, so it can't call any of the methods in it, unless they are overridden versions of the methods already within the base class: it's like a generic Fruit trying to call a "Orange Segment" method on a Grape! Laugh | :laugh:
The chances are that wanting to do this is a symptom of a bad design choice.
 

There are a couple of was you can do it though if you must. Have a look here: http://stackoverflow.com/questions/887178/content-page-class-method-calling-from-master-page-class[^]
  Permalink  
Comments
Member 8214635 at 21-Jan-13 15:32pm
   
No. i think you didnt get a point. i create 1 class file. class.cs which has some function i was try to call these function in a masterpage.master.cs file.
OriginalGriff at 21-Jan-13 15:39pm
   
Yes I did... Follow the link!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This goes into your MasterPage class:
if(Page is Default)
{
   Default def = (Default)Page;
   def.yourFunction();
}
 
Best regards
Espen Harlinn
  Permalink  
Comments
Member 8214635 at 21-Jan-13 15:51pm
   
please help me out i didn't undeerstand please!!
 
this is my masterpage.master.cs code :
using ASP;
using BusinessLayer;
using DataLayer;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxPopupControl;
using System;
using System.Data;
using System.Text;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
 
public partial class NewFolder1_MasterPage : System.Web.UI.MasterPage
{
protected HtmlAnchor aLogin;
protected Button BtnSearch;
protected ContentPlaceHolder ContentPlaceHolder1;
protected HtmlGenericControl DivCoursemenu;
protected HtmlGenericControl divSubAdmin;
protected HtmlGenericControl dvContent;
protected HtmlGenericControl dvNews;
protected HtmlForm form1;
protected HtmlHead Head1;
protected HiddenField HfScholarshipImage;
protected HiddenField hfTagline;
protected HyperLink hid;
protected HiddenField hLogo1;
protected HiddenField hLogo2;
protected ASPxLabel lblAdmissionOpenText;
protected ASPxLabel lblAuthorizedLC;
protected ASPxLabel lblNewBatchText;
protected HtmlGenericControl leftBarMenu;
protected HtmlGenericControl lisubAdmin;
protected Literal litAdmissionOpenImage;
protected Literal litNewBatch;
protected HtmlGenericControl LitTopTagLine;
protected Literal litVirtualTourImageHomePage;
protected Literal ltSlideShow2;
protected DevExpress.Web.ASPxPopupControl.ASPxPopupControl pcMain;
protected PopupControlContentControl PopupControlContentControl1;
protected usercontrol_queryform4contactus_ascx QueryForm4Contactus1;
protected usercontrol_queryform4scholarship_ascx QueryForm4Scholarship1;
protected ScriptManager ScriptManager1;
protected TextBox txtBxSearch;
 
protected void BtnSearch_Click(object sender, EventArgs e)
{
if (this.txtBxSearch.Text.Length > 0)
{
base.Response.Redirect("SiteSearch.aspx?search=" + this.txtBxSearch.Text);
}
else
{
this.Page.RegisterStartupScript("msg", "<script> alert( 'Kindly Enter word to search')</script>");
}
}
 
private void fillCoursemenu()
{
Conversion conversion = new Conversion();
Course_CategoryBo bo = new Course_CategoryBo();
Course_SubCategoryBo bo2 = new Course_SubCategoryBo();
StringBuilder builder = new StringBuilder();
DataTable table = bo.GetActiveCourse_Category();
builder.Append("<ul>");
if ((table != null) && (table.Rows.Count > 0))
{
for (int i = 0; i < table.Rows.Count; i++)
{
if (conversion.ConToStr(table.Rows[i]["Name"]) != "")
{
bo2._CourseId = conversion.ConToInt64(table.Rows[i]["Id"]);
DataTable table2 = bo2.ActiveCourse_SubCategory();
if ((table2 != null) && (table2.Rows.Count > 0))
{
builder.Append("<li><span style='color: #000000; font-weight: bold;'>" + conversion.ConToStr(table.Rows[i]["Name"]) + "</span>");
builder.Append("<div><ul>");
for (int j = 0; j < table2.Rows.Count; j++)
{
if (conversion.ConToStr(table2.Rows[j]["Name"]) != "")
{
builder.Append(" <li><span style='color: #000000; font-weight: bold;'>" + conversion.ConToStr(table2.Rows[j]["Name"]) + "</span></li>");
}
}
builder.Append("</ul></div>");
builder.Append("</li>");
Espen Harlinn at 21-Jan-13 16:01pm
   
Please try to tell me what you are trying to accomplish, looks like you have the DevExpress components on your hands, which includes ASPxMenu if you need a menu, and ASPxGridView if you need to build a table, or a set of nested tables - and I assume that you have xpo too, and if you're lucky xaf - which is what you should use if you have it ...
Member 8214635 at 23-Jan-13 14:35pm
   
hi Espen,
 
can you simply help me how can i add a metatag in aspx from body section to head section using javascript. because the website which on i work its totally dynamic all html page body section is generated from database but head section is generated by a.aspx.cs page in which some class function is calling. and whole website is compiled and all pages dll's has been created. So, now i tried to add a meta tag from aspx page but it is not working. Now i want to try using some javascript code to add meta tag. i store JS code in database from where body section is created. So, i tried to create a meta tag from javascript. If youhave any other idea for adding meta tag and any solution for creating meta tag from javascript so pls help me.. it is to important that all about my career...
 
Thanks in advance
Espen Harlinn at 23-Jan-13 14:51pm
   
Have a look at the ScriptManager : http://msdn.microsoft.com/en-us/library/bb398863(VS.100).aspx or the ScriptManagerProxy http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanagerproxy(VS.100).aspx
 
I would be surprised if the ScriptManager is not used, and I expect that the ScriptManagerProxy is what you are looking for. Use ScriptManagerProxy.Scripts to register a ScriptReference to you JavaScript file for use with your asp.net page.
Member 8214635 at 23-Jan-13 16:26pm
   
hi Espen, thanks for post...
 
can i send you the file. then you better understand what i want? Please...
Espen Harlinn at 23-Jan-13 16:35pm
   
I can't promise anything, but you can send it to my goodtech mail address
Member 8214635 at 23-Jan-13 17:01pm
   
ok thanks. But please try! i was send you a downloading link. right now it was uploading. with in half hour you get a link please download it from there. Just try to add meta tag in it. if it is possible.
Member 8214635 at 23-Jan-13 16:31pm
   
Espen,
 
it is possible! if i was create one new page and add meta tag on it and it send meta tag in all pages!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid