Click here to Skip to main content
15,917,454 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public static void TrustedForm()
{
    char doubleQuote = '"';
    if (ViewState["OfferID"].ToString() == "992")
    {
        trustedFormScript = "<script src=" + doubleQuote + "http://api.trustedform.com/trustedform.js?field=trustedformfield"
        + doubleQuote + "  type=" + doubleQuote + "text/javascript" + doubleQuote + "></script>";
    }
}

public partial class Offer : BaseForm
{
    public partial class Admin_EditCompaign : System.Web.UI.Page
    {
        protected void btnUpdate_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton oButton = (ImageButton)sender;

            if (oButton.ID == "btnUpdatePostingSetUp")
            {
                if (ddlMethod.SelectedValue != "File")
                {
                    if (txtClientPostURL.Text.Trim().Length == 0)
                    {
                        //ClientScript.RegisterClientScriptBlock(GetType(), "PostURL", "alert('Client Post URL required')", true);
                        //return;
                    }
                }
            }

            if (IsValid)
            {
                SaveData();
                SetTabVisibility(true);

            }

            SelectTab(oButton.ID);

            //Trusted form if checked
            if (chkTrustedForm.Checked)
            {
                
            }
        }
    }
}


What I have tried:

I have declared the method
C#
public static void TrustedForm()
above existed if condition in
C#
Offer.aspx.cs
page.

I want to call that method in
C#
Admin/EditCampaign.aspx.cs
page.

Problem is I dont get intellisense to call
C#
Offer.TrustedForm()
in EditCampaign page and get error:
A namespace cannot directly contain members like fields or methods
in Offer page

Tried using static and without static declaring the instance still no use. Please assist me on this.

Code above shown: trustedform method in offer page , top part of offer page, top part of Admin/editCampaign page and place where I want to call the method
C#
//Trusted form if checked
if (chkTrustedForm.Checked)
{
    
}
Posted
Updated 6-May-22 7:23am
v3

you need to follow basically 3 steps.

1. if your class is in dll then take reference of the dll to your solution file.
2. use "using <namespace>;" to the header of your class.
3. call the method using alias or with classname.methodName if static method.

Regards,
Avinash kumar
 
Share this answer
 
v2
Comments
Amith 12807185 15-Nov-16 4:53am    
No class is not in dll. It was downloaded from ftp server and solution was built.
Tried rest of the steps but still I 'am unable to access that method in editcampaign page.So I tried to define trustedForm function outside pageload event taking out static, there is no error now, however i still couldn't access the function in another .cs file
The file itself has no significance, for the method to be a part of the Offer class it has to be inside its class declaration, not just in the same file

C#
public partial class Offer : BaseForm
{
    public static void TrustedForm()
    {
        // your code here
    }

    // rest of Offer code here
}
 
Share this answer
 
Comments
Amith 12807185 15-Nov-16 5:00am    
I defined the method outside pageload event removed static, now it is not throwing any error but that method still not available in editCampaign page.[the type or namespace name 'offer' couldn't be found] while declaring the instance. Seriously not knowing what to do? Please let me know if u want some more info on the prob.
F-ES Sitecore 15-Nov-16 8:19am    
If the offer page is in a different folder it will be in a different namespace so you can't just use "Offer", you'll need to add the appropriate "Using" statement at the top of the page, or use the fully qualified class name like

MyWholeNamespace.Offer

Accessing one class from another really is .net 101 and if you're struggling to do this you need to get a book on c# and learn the fundamentals.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900