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

  • SEARCH
  • Home
  • 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 3210968
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:38:57+00:00 2026-05-17T14:38:57+00:00

I have created a user control UserVote that has property to find total vote

  • 0

I have created a user control UserVote that has property to find total vote on particular question.

Now I want to call it from an aspx page.

The control code-behind (UserVote.ascx.cs) looks like:

public partial class UserVote : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dtVoteInfo = ShowVoteDetail(objectType, objectId);
        if (dtVoteInfo != null)
        {
            if (dtVoteInfo.Rows.Count > 0)
            {
                int.TryParse(dtVoteInfo.Rows[0]["TOTAL_VOTE"].ToString(), out currentVote);
                int.TryParse(dtVoteInfo.Rows[0]["MY_VOTING"].ToString(), out myVoting);
            }
        }
        ltrVotes.Text = currentVote.ToString();
        hfCurrentVote.Value = currentVote.ToString();
        hfMyVote.Value = myVoting.ToString();

        // ...snipped for brevity...
    }
}

The control markup (UserVote.ascx) looks like:

<div class="vote-cell" style="width: 46px; height: 92px">
  <img src ="~/UserControls/Vote/Images/Arrow Up.png" 
        id = "voteupoff" 
        runat = "server" alt ="vote up" 
        class="voteupImage" 
        style="height: 45px; width: 45px"/>
  <div class="vote" style ="text-align:center; color:#808185;font-weight:bold;">
    <asp:Literal ID="ltrVotes" runat="server" ></asp:Literal>
  </div>
  <img  src ="~/UserControls/Vote/Images/arrow_down.png" 
        id ="votedownoff" 
        runat = "server" alt = "vote down"
        class = "votedownImage" 
        style="height: 45px; width: 44px; margin-left: 0px;" />
</div>

My page code-behind (viewanswer.aspx.cs) looks like:

UserVote Voteing = (UserVote) **what i write here...**.findcontrol(voting)
Voteing.objectType =300;
Voteing.object id= 2;

My page markup (viewanswer.aspx) looks like:

<klmsuc:Voteing ID="Voteing" runat="server" />
  • 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-17T14:38:58+00:00Added an answer on May 17, 2026 at 2:38 pm

    Not sure if you’re trying to access the currentVote value in the usercontrol from your ASPX page but if you are:

    public partial class UserVote : System.Web.UI.UserControl
    {
        private int _currentVode;
        private int _myVoting;
    
        // Move data access to OnInit because this otherwise Page_Load on page
        // fires before control Page_Load.
        protected override void OnInit(EventArgs e)
        {
            DataTable dtVoteInfo = ShowVoteDetail(objectType, objectId);
            if (dtVoteInfo != null)
            {
                if (dtVoteInfo.Rows.Count > 0)
                {
                    int.TryParse(dtVoteInfo.Rows[0]["TOTAL_VOTE"].ToString(), 
                                out _currentVote);
                    int.TryParse(dtVoteInfo.Rows[0]["MY_VOTING"].ToString(), 
                                out _myVoting);
                }
            }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            ltrVotes.Text = _currentVote.ToString();
            hfCurrentVote.Value = _currentVote.ToString();
            hfMyVote.Value = _myVoting.ToString();
    
            // set img src snipped for brevity....
        }
    
        public int CurrentVote
        {
            get { return _currentVote; }
        }
    
        public int MyVoting
        {
            get { return _myVoting; }
        }
    }
    

    On the ASPX page add the following directive to register the control:

    <%@ register src="~/UserVote.ascx" tagprefix="klmsuc" tagname="Voteing" %>
    
    <!-- You had this already -->
    <klmsuc:Voteing ID="Voteing" runat="server" />
    

    In your ASPX code-behind:

    int currentVote = Voteing.CurrentVote;
    int myVote = Voteing.MyVoting;
    

    If you’re using VS2008 or later you shouldn’t have to use FindControl. If you do then see Willem’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a user control (CheckedDirTree) that exposes a CheckedFolder property which in
I have created a user control, and now I want to add custom properties
I have created a User Control in my application that has a textbox and
I have created a user control that has an asp:login control in it. I
I have created a user control (link) which has a label and a button.
I have a user control that I've created, however when I go to add
I have two User Controls already created now I want to use one as
I have created a user control that contains a button. I am using this
I have created a user control on winform where i want to display some
I have created a User Control with 4 check boxes(server control). I want to

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.