Click here to Skip to main content
14,327,288 members
   

ASP.NET

 
AnswerRe: Want to learn React.Js Pin
jkirkerx3-Jan-19 14:00
professionaljkirkerx3-Jan-19 14:00 
Question.net 2 BindingSources to same DataTable Pin
rjto19-Dec-18 12:01
memberrjto19-Dec-18 12:01 
AnswerRe: .net 2 BindingSources to same DataTable Pin
David Mujica1-Jan-19 13:10
memberDavid Mujica1-Jan-19 13:10 
GeneralRe: .net 2 BindingSources to same DataTable Pin
rjto2-Jan-19 4:58
memberrjto2-Jan-19 4:58 
QuestionHow to move cursor to end of iframe contenteditable Pin
Member 1408886515-Dec-18 11:42
memberMember 1408886515-Dec-18 11:42 
QuestionHow to focus cursor at the end of iframe body content when page loads Pin
Member 1408886513-Dec-18 10:59
memberMember 1408886513-Dec-18 10:59 
AnswerRe: How to focus cursor at the end of iframe body content when page loads Pin
F-ES Sitecore13-Dec-18 23:35
mveF-ES Sitecore13-Dec-18 23:35 
QuestionTwo Issues with Custom Control with ASP.NET Site Pin
Dominick Marciano11-Dec-18 11:31
professionalDominick Marciano11-Dec-18 11:31 
Good Afternoon,

I am working on a project where I will need a custom control added to a site. Since I have never worked with them previously, I decided to try and make a very basic control and a test site so I can learn how to do everything properly. For instructions, I was using the steps outlined on Microsoft's website here. Therefore I created a solution with two projects - Custom Control Assembly and Custom Control Test Site, both of which are using the 4.7 version of the .NET Framework.

For the Custom Control Assembly, the Assembly name is CustomControlAssembly and the Default namespace is CustomControlNamepsace. There is one file in the project called CustomControl which inherits from
System.Web.UI.Control
. This project built without any errors and I copied the CustomControlAssembly.dll to the /Custom Control Test/Custom Control Test Site/bin folder as instructed on the Microsoft page listed above.

The Custom Control Test Site is a web forms site. On the Default.aspx page I added the following directive right underneath the
<%@ Page %>
directive:

<%@ Register TagPrefix="Custom" Namespace="CustomControlNamespace" Assembly="CustomControlAssembly" %>


In the page, I am able to add the following tag and IntelliSense correctly finds it:

<Custom:CustomControl runat="server"></Custom:CustomControl>


However, if I try to add an ID properties (in order to name it like I do with all ASP.NET controls), like the following:

<Custom:CustomControl runat="server" ID="CustomControl1"></Custom:CustomControl>


I get the following error message:

CS0400 - The type or namespace name 'CustomControlNamespace' could not be found in the global namespace (are you missing an assembly reference?)

If I take the ID="CustomControl1" out of the tag, then the site will build fine again. However, when I run the site, the custom control does not show anything on the site. I tried updating the CustomControl to inherit from
System.Web.UI.UserControl
instead of
System.Web.UI.Control
but it still doesn't display on the Default.aspx page. The following is the markup of the CustomControl.ascx file:

<pre><%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CustomControl.ascx.cs" Inherits="CustomControlNamespace.CustomControl" %>
<table>
    <tr>
        <td>First Name:</td>
        <td><asp:TextBox runat="server" ID="txtFirstName"></asp:TextBox></td>
    </tr>
    <tr>
        <td>Last Name:</td>
        <td><asp:TextBox runat="server" ID="txtLastName"></asp:TextBox></td>
    </tr>
    <tr>
        <td colspan="2" style="text-align: center"><asp:Button runat="server" ID="btnShowName" Text="Show Name" OnClick="btnShowName_Click"/></td>
    </tr>
</table>
<br/>
<br/>
<asp:Label runat="server" ID="lblFullName"></asp:Label>


And the code-behind is:
using System;

namespace CustomControlNamespace
{
    public partial class CustomControl : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnShowName_Click(object sender, EventArgs e)
        {
            string firstName = txtFirstName.Text.Trim();
            string lastName = txtLastName.Text.Trim();
            string fullName = $"Hello {firstName} {lastName}!  If you are seeing this message, then the custom control " +
                              $"is working successfully.";
            lblFullName.Text = fullName;
        }
    }
}


So I have two errors - First, why can't I added an ID to the custom control and second, and more importantly, why is the custom control not showing on the Default.aspx page even though the control and site built fine, without any errors or warning. Even when I inspect the HTML of the Default.aspx page, where the control should be, it is just empty.

Any help, guidance, or suggestions would be greatly appreciated. I have been at this for over an hour and a half and can't find anything that would explain why these issues are occurring. Thanks in advance for any help you can provide.
A black hole is where God tried to divide by zero.

There are 10 kinds of people in the world; those who understand binary and those who don't.

QuestionHow do I download files in background or do asynchronous process in MVC Pin
Member 140250634-Dec-18 15:39
memberMember 140250634-Dec-18 15:39 
AnswerRe: How do I download files in background or do asynchronous process in MVC Pin
F-ES Sitecore5-Dec-18 0:39
mveF-ES Sitecore5-Dec-18 0:39 
AnswerRe: How do I download files in background or do asynchronous process in MVC Pin
Richard Deeming5-Dec-18 9:25
mveRichard Deeming5-Dec-18 9:25 
GeneralRe: How do I download files in background or do asynchronous process in MVC Pin
Member 140250636-Dec-18 19:45
memberMember 140250636-Dec-18 19:45 
AnswerRe: How do I download files in background or do asynchronous process in MVC Pin
Nitin Sawant28-Dec-18 2:16
professionalNitin Sawant28-Dec-18 2:16 
Questionwtx-context attribute Pin
DerekT-P4-Dec-18 8:27
professionalDerekT-P4-Dec-18 8:27 
AnswerRe: wtx-context attribute Pin
Member 1451533928-Jun-19 3:05
memberMember 1451533928-Jun-19 3:05 
GeneralRe: wtx-context attribute Pin
DerekT-P28-Jun-19 4:17
professionalDerekT-P28-Jun-19 4:17 
QuestionInsert HTML Elements In A DIV In VB WebForm Dynamically Using jQuery Pin
MadDashCoder30-Nov-18 19:15
memberMadDashCoder30-Nov-18 19:15 
AnswerRe: Insert HTML Elements In A DIV In VB WebForm Dynamically Using jQuery Pin
F-ES Sitecore2-Dec-18 23:02
mveF-ES Sitecore2-Dec-18 23:02 
QuestionHaving difficulty with an MVC question Pin
Member 1406015930-Nov-18 7:25
memberMember 1406015930-Nov-18 7:25 
AnswerRe: Having difficulty with an MVC question Pin
Dave Kreskowiak30-Nov-18 7:59
mveDave Kreskowiak30-Nov-18 7:59 
GeneralRe: Having difficulty with an MVC question Pin
Member 1406015930-Nov-18 8:31
memberMember 1406015930-Nov-18 8:31 
GeneralRe: Having difficulty with an MVC question Pin
Richard MacCutchan30-Nov-18 22:25
protectorRichard MacCutchan30-Nov-18 22:25 
GeneralRe: Having difficulty with an MVC question Pin
Vincent Maverick Durano5-Dec-18 15:07
mveVincent Maverick Durano5-Dec-18 15:07 
QuestionDebugging a Web API Project in Visual Studio 2017 Pin
Dominick Marciano26-Nov-18 5:13
professionalDominick Marciano26-Nov-18 5:13 
AnswerRe: Debugging a Web API Project in Visual Studio 2017 Pin
maryam.saboor4-Dec-18 23:36
professionalmaryam.saboor4-Dec-18 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.