Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6975519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:22:43+00:00 2026-05-27T17:22:43+00:00

For a site I’m developing I have two html buttons, not ASP because I

  • 0

For a site I’m developing I have two html buttons, not ASP because I do not want them to postback. For the submit button I am calling a javascript function that implements PageMethods to call a C# method from the codebehind. Here is the code for the buttons and the javascript.

<fieldset id="Fieldset">
    <button onclick="SendForm();">Send</button>             
    &nbsp;
    <button onclick="CancelForm();">Cancel</button>                  
</fieldset>

<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" EnablePartialRendering="true" runat="server" />

<script type="text/javascript">
    function SendForm() {
        var email = $get("txtEmail").value;

        PageMethods.SendForm(email, OnSucceeded, OnFailed);
    }

    function OnSucceeded() {
        $get("Fieldset").innerHTML = "<p>Thank you!</p>";
    }

    function OnFailed(error) {
        alert(error.get_message());
    }
</script>

The codebehind method shown here:

[WebMethod]
public static void SendForm(string email)
{
    if (string.IsNullOrEmpty(email))
    {
        throw new Exception("You must supply an email address.");
    }
    else
    {
        if (IsValidEmailAddress(email))
        {
            bool[] desc = new bool[14];
            bool[] local = new bool[14];
            bool[] other = new bool[14];

            for (int i = 1; i <= 14; i++)
            {
                desc[i] = ((CheckBox)Page.FindControl("chkDesc" + i.ToString())).Checked;
                local[i] = ((CheckBox)Page.FindControl("chkLocal" + i.ToString())).Checked;
                other[i] = ((CheckBox)Page.FindControl("chkOther" + i.ToString())).Checked;

                /* Do stuff here */
            }
        }
        else
        {
            throw new Exception("You must supply a valid email address.");
        }
    }
}

does not work unless it is declared as static. Declaring it as static blocks me from checking the checkboxes on the page because it generates a “An object reference is required for the non-static field, method, or property” error. So my problem can be fixed from either of two directions. A) Is there a way I can have this method work without declaring it as static? B) How do I check the checkboxes if the method is static.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:22:44+00:00Added an answer on May 27, 2026 at 5:22 pm

    It has to be static, no way around that; But you can access the Page like this

    Page page = HttpContext.Current.Handler as Page;
    

    and do FindControl on this page instance.

    desc[i] = ((CheckBox)page.FindControl("chkDesc" + i.ToString())).Checked;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
Our site is using ASP.Net Membership. I have a page which literally has nothing
A site I'm working on has Flash headers (using swfobject to embed them). Now
The site I'm working on is using a Databound asp:Menu control. When sending 1
Site structure: / /products /products/design /products/photo /about I want to see parent menu item
Site which I am developing has a menu with drop downs, which is always
My site is running in LAMP, my image CDN is in nginx. I want
My site (ASP.NET + C#) has FAQ data pull from another site's web service
Site: http://sebastiano.freehostia.com/ CSS: /style.css I'm not overly sure what's going wrong with the positioning
Site: is here picture html: <img alt= src=UserFiles/Image/galerie/12970854473D-Eco-60.jpg> when I add border: 2px solid

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.