i have a asp.net webform app with employees.aspx and a user control usercontrol1.ascx as follows
employees.aspx
i have placed usercontrol1.ascx inside my employees.aspx and i need to run a function get_employees() which is inside employees.aspx
usercontrol1.ascx
<%# Control Language="vb" AutoEventWireup="false" CodeBehind="usercontrol2.ascx.vb" Inherits="wogapp.usercontrol1" %>
<asp:Button ID="btnEmpDetails" runat="server" Text="Employee Details" class="btn btn-primary" />
Related
I have created .Master, .aspx and .ascx pages. I want to call .ascx page upon click on button in .master page. If the button is not clicked then .ascx should not show up.
Currently, Onload of page, .ascx page is calling because i have used <uc1:Account runat="server" ID="Account" />. But i want after click of button not on page load.
Any help is highly appreciated. Thank you in advance.
My master page looks like this:
<%# Master Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Staff.master.cs" Inherits="Admin_Staff" %>
<%# Register Src="~/Controls/Account.ascx" TagPrefix="uc1" TagName="Account" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<h4>Account</h4>
<span class="input-group-btn">
<input type="text" class=" search-query form-control" placeholder="Search" />
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
</span>
<div class="col-lg-9">
<uc1:Account runat="server" ID="Account" />
</div>
</asp:Content>
My User Control looks like this:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="Acc.ascx.cs" Inherits="Admin_Controls_Account" %>
<asp:panel id="pnlAcc" runat="server">
<section id="AccForm">
<asp:PlaceHolder runat="server" ID="PlaceHolder1" Visible="false">
</asp:PlaceHolder>
<div class="form-group">
<asp:Label runat="server" CssClass="col-md-2 control-label">Country: </asp:Label>
<div class="col-md-10">
<asp:Label runat="server" CssClass="col-md control-label" >New Zealand</asp:Label>
</div>
</div>
</section>
</asp:panel>
My .aspx page
<%# Page Title="" Language="C#" MasterPageFile="~/Admin/Staff.master" AutoEventWireup="true" CodeFile="Staff.aspx.cs" Inherits="Admin_Staff" %>
<asp:Content ID="Content1" ContentPlaceHolderID="StaffContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent1" Runat="Server">
</asp:Content>
You can set the Visibility of the Control to false and change it on Button Click
<uc1:Account runat="server" ID="Account" Visible="false" />
And then on button click
protected void Button1_Click(object sender, EventArgs e)
{
Account.Visible = true;
}
Or you can add the Controls dynamically
protected void Button1_Click(object sender, EventArgs e)
{
Admin_Controls_Account account = (Admin_Controls_Account)LoadControl("~/Controls/Account.ascx");
PlaceHolder1.Controls.Add(account);
}
Note that for the last option you will have to reload the control each time there is a PostBack so you will have to store the Visibility yourself and recreate the control each time the page is loaded.
Simple way is to make the control invisible on the master page.
<uc1:Account runat="server" ID="Account" Visible="False" />
Make it visible on button click.
In my webpage I use two user controls:
ucControl1 and ucControl2. The ucControl1 control also contains an instance of the ucControl2 control inside it.
When you run the application and go to the page in question, it appears that only the instance that is inside the ucControl1 is working correctly. When trying to execute the functionality of the ucControl2 that is directly on the page, it correctly executes the backend code, opens the modal correctly but does not show the results on the screen.
What could be happening?
The page is like this
<%# Page Language="C#" AutoEventWireup="true" CodeFile="PageSample.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="PageSample" %>
<%# MasterType VirtualPath="~/MasterPage.master" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc2" TagName="ucControl2" %>
<%# Register Src="~/Controls/ucControl1.ascx" TagPrefix="uc1" TagName="ucControl1" %>
<asp:Content runat="server" ContentPlaceHolder ID="cpSampleID">
<div>
<uc1:ucControl2 runat="server" ID="uc2" />
</div>
<uc1:ucControl1 runat="server" ID="uc1" />
</asp:Content>
And the usercontrol1
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ucControl1.ascx.cs" Inherits="ucControl1" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc1" TagName="ucControl2" %>
<%-- Something Something Something --%>
<uc1:ucControl2 runat="server" ID="ucControl2" />
I've found a solution. The modal is opened by javascript.
ucControl2
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ucControl2.ascx.cs" Inherits="ucControl2" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc2" TagName="ucControl2" %>
<div id="modal">
<!-- Some Textboxes -->
</div>
Method to open the modal
public void OpenModal()
{
string id = "modal";
string js = $#"
$(document).ready(function() {{
if ($('.modal.in').length > 0) {{
$('.modal').on('hidden', function() {{
$('.modal').off('hidden');
$('#{id}').modal({{show: true, keyboard: false, backdrop: 'static'}});
}});
$('.modal').modal('hide');
}} else {{
$('#{id}').modal({{show: true, keyboard: false, backdrop: 'static'}});
}}
}});";
ScriptManager.RegisterStartupScript(this, this.GetType(), id, js, true);
}
So when the control is called, the javascript does not know which of the controls should open, and in this case it is opening the first control that is on the page.
To solve it I've changed the div through an asp panel, in this way asp generates a different client ID for each control and the controls are displayed correctly.
I got one problem, I have three user controls say Control1,control2, control3.
I want to make Control1 into 3 divs and see contol1 UI in first part
control2-2nd part of div
Control3- in 3 Part of div
Is it possible?
I wanted to do this just for the sake i can maintain with less code .Is there any alternative .other this which will suit me best.
Please suggest
Yes, you can put multiple user control on a single user control. However your question is down voted the solution of your problem is as given below :
Create a sample website. Add Webusercontrol1.ascx ,Webusercontrol2.ascx, Webusercontrol3.ascx, Webusercontrol4.ascx in it and modify the code as given below.
Default.aspx page html
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="SO_1._Default" %>
<%# Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
</asp:Content>
UserControl-1 Html : This is container user control and this will have all required user control on it.
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs"
Inherits="SO_1.WebUserControl1" %>
<%# Register Src="WebUserControl1.ascx" TagName="WebUserControl2" TagPrefix="uc1" %>
<%# Register Src="WebUserControl2.ascx" TagName="WebUserControl2" TagPrefix="uc2" %>
<%# Register Src="WebUserControl3.ascx" TagName="WebUserControl3" TagPrefix="uc3" %>
<%# Register Src="WebUserControl4.ascx" TagName="WebUserControl4" TagPrefix="uc4" %>
<p>
<b>DIV-1 Container User control</b></p>
<div>
<b>DIV1</b>
<br />
<uc2:WebUserControl2 ID="WebUserControl21" runat="server" />
</div>
<div>
<b>DIV2</b>
<br />
<uc3:WebUserControl3 ID="WebUserControl31" runat="server" />
</div>
<div>
<b>DIV3</b>
<br />
<uc4:WebUserControl4 ID="WebUserControl41" runat="server" />
</div>
UserControl-2 html
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="SO_1.WebUserControl2" %>
User Control-1
UserControl-3 html
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="SO_1.WebUserControl2" %>
User Control-2
UserControl-4 html
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="SO_1.WebUserControl2" %>
User Control-3
My tab control items contain three different pages.Clicking on tabitem ,they are visible,but when want to perform javascript event on page item then problem arise.javascript well works for only first tab control item,rest of them are not work.Show me the bellow error.
Microsoft JScript runtime error: 'this.GetStateInput().value' is null or not an objec
tabcontrol
**tab item1 contain page1
tab item2 contain page2
tab item3 contain page3**
i write javascript on page1 control,it's work well but rest of pages javascript show the above error message. i work on devexpress control
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="UCCharge.ascx.cs" Inherits="WebCore.UserControls.ChargeSettings.UCCharge" %>
<%# Register assembly="DevExpress.Web.v9.1, Version=9.1.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxTabControl" tagprefix="dxtc" %>
<%# Register assembly="DevExpress.Web.v9.1, Version=9.1.2.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073" namespace="DevExpress.Web.ASPxClasses" tagprefix="dxw" %>
<%# Register src="UCConfig_Charge_Company_Wise.ascx" tagname="UCConfig_Charge_Company_Wise" tagprefix="uc1" %>
<%# Register src="UCConfig_Charge_Depository_Company_Wise.ascx" tagname="UCConfig_Charge_Depository_Company_Wise" tagprefix="uc2" %>
<%# Register src="UCconfig_charge_operation_mode.ascx" tagname="UCconfig_charge_operation_mode" tagprefix="uc3" %>
<%# Register src="../InvestorAccount/UCconfig_Investor_Account_Wise_Charge.ascx" tagname="UCConfig_Investor_Account_Wise_Charge" tagprefix="uc4" %>
<table>
<tr>
<td>
<dxtc:ASPxPageControl Width="500px" ID="ASPxPageControl1" runat="server" ActiveTabIndex="0"
EnableCallbackCompression="True" EnableHierarchyRecreation="True"
AutoPostBack="True">
<TabPages>
<dxtc:TabPage Text="Charge Company">
<ContentCollection>
<dxw:ContentControl ID="ContentControl1" runat="server">
<uc1:UCConfig_Charge_Company_Wise ID="UCConfig_Charge_Company_Wise" runat="server" />
</dxw:ContentControl>
</ContentCollection>
</dxtc:TabPage>
<dxtc:TabPage Text="Charge Depository Company">
<ContentCollection>
<dxw:ContentControl ID="ContentControl3" runat="server">
<uc2:UCConfig_Charge_Depository_Company_Wise ID="UCConfig_Charge_Depository_Company_Wise"
runat="server" />
</dxw:ContentControl>
</ContentCollection>
</dxtc:TabPage>
<dxtc:TabPage Text="Investor Charge ">
<ContentCollection>
<dxw:ContentControl ID="ContentControl5" runat="server">
<uc4:UCConfig_Investor_Account_Wise_Charge ID="UCConfig_Investor_Account_Wise_Charge"
runat="server" />
</dxw:ContentControl>
</ContentCollection>
</dxtc:TabPage>
<dxtc:TabPage Text="Charge Operation Mode ">
<ContentCollection>
<dxw:ContentControl ID="ContentControl4" runat="server">
<uc3:UCconfig_charge_operation_mode ID="UCconfig_charge_operation_mode"
runat="server" />
</dxw:ContentControl>
</ContentCollection>
</dxtc:TabPage>
</TabPages>
</dxtc:ASPxPageControl>
</td>
</tr>
</table>
I read on a Support issue of a user getting this error, in his case it was because he was using value (myTextBox.value) when getting the value of a DX Control instead of the GetValue() (myTextBox.GetValue()) client method DX provides. Could this be the same thing happening in your code as well?
When I use a ASP:Calendar control, and give it an ID:
<asp:Calendar runat="server" ID="MyCal" />
It looks like this in the rendered html:
<table id="NameMangled_MyCal"... />
And I can access the element by ID in javascript like this:
var cal= document.getElementById("<%= MyCal.ClientID%>")
However, When I make a custom user control that has-a calendar:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WeeklyEventsCalendar.ascx.cs"
Inherits="WeeklyEventsCalendar" %>
<div>
<asp:Calendar runat="server" ID="InnerCal" Width="100%" OnDayRender="RenderCell" OnVisibleMonthChanged="ChangeMonth" Height="480px" />
</div>
And then give it an ID when I add it to my page...
<mvs:WeeklyEventsCalendar ID="WeeklyCal" runat="server" />
That ID doesn't show up anywhere in the rendered HTML. all I get is
<div> stuff </div>
When I want
<div id="NameMangled_WeeklyCal"> stuff <div>
What am I doing wrong?
UserControls only render their contents, nothing else. What you could do is
<%# Control Language="C#" AutoEventWireup="true" CodeFile="WeeklyEventsCalendar.ascx.cs"
Inherits="WeeklyEventsCalendar" %>
<div id="<%= this.ControlID %>">
<asp:Calendar runat="server" ID="InnerCal" Width="100%" OnDayRender="RenderCell" OnVisibleMonthChanged="ChangeMonth" Height="480px" />
</div>