how do i make any aspx page as a user control in asp.net?
I have one page called myimage.aspx whic开发者_如何学编程h creates random captcha image ,
<form id="form1" runat="server">
<div>
<%--<img src="MyImagePage.aspx">--%> //using normal page...this is working fine
<ucImage:ucMyImage ID="myimage" runat="server" /> //using usercontrol this gives me image but following textboxes , buttons ans labels are disappears :(
<asp:TextBox id="CodeNumberTextBox" runat="server"></asp:TextBox>
<asp:Button id="SubmitButton" runat="server" Text="Submit"></asp:Button><br>
<asp:Label ID="lblMessage" runat="server" Text="CORRECT!" Visible="false"></asp:Label>
</div>
</form>
i called that page on my index.aspx page like this <img src="MyImageControl.ascx">
.
But instead of aspx page i have created it as a usercontrol myimagecontrol.ascx
and put it into index.aspx like <ucImage:ucMyImage ID="myimage" runat="server" />
also add <%@ Register %> tag too, but I'm only able to view image captcha not any other contains of index.aspx page like textbox or others button,
please tell me whats wrong???
Just open the design view and drag your control on the page where ever you want to call it Make sure it is in design view.
From my ASPX page
<%@ Register TagName="uc" TagPrefix="uc1" Src="~/WebUserControl.ascx"%>
<uc1:uc ID="uc" runat="server" />
<asp:Label ID="lbl" runat="server">Loaded after UC</asp:Label>
From my UserControl
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:Label ID="lbl" runat="server"></asp:Label>
I have no issues what so ever. I don't see why your controls won't render because of the usercontrol. There must something in your codebehind which interferes with the rendering of your controls
Hi :) I think there may b issue in rendering, Here i am posting my code which is working
For user Control (ascx)
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %>
<p>
<img alt="" src="" runat="server" id="image"/> </p>
<asp:Button ID="Button1" runat="server" Text="Button" /><asp:LinkButton ID="LinkButton1"
runat="server">LinkButton</asp:LinkButton>
For AspX (Registering User Control)
<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
For Using the Image Tag in Aspx
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
精彩评论