I am truing to use a Telerik List View. I just added a SqlDataSource and I want to give the select command at server side. But when i want to access it in .cs file SqlDataSource1 is not accessible even any control is not showing. I added a label when i tried Label1.Text than label1 is not accessible in .cs file.
<%# Page Title="" Language="C#" MasterPageFile="~/PortalSite.Master" AutoEventWireup="true" CodeBehind="category.aspx.cs" Inherits="NoidaPortal.category" %>
<%# Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.rdpWrap .RadInput, .rdpWrap .rdpPagerButton, .rdpWrap .rdpPagerLabel
{
float: left;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource>
<div>
<!-- content start -->
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function RequestStart(sender, eventArgs) {
//disable ajax on update/insert operation to upload the image
if ((eventArgs.get_eventTarget().indexOf("Update") > -1) || (eventArgs.get_eventTarget().indexOf("PerformInsert") > -1)) {
eventArgs.set_enableAjax(false);
}
}
</script>
</telerik:RadCodeBlock>
<table>
<tr>
<td>
<asp:Panel ID="ListViewPanel1" runat="server">
<telerik:RadListView ID="RadListView1" DataSourceID="SqlDataSource1" runat="server"
ItemPlaceholderID="CustomersContainer" DataKeyNames="ArchitectId" AllowPaging="True"
>
<LayoutTemplate>
<!-- Set the id of the wrapping container to match the CLIENT ID of the RadListView control to display the ajax loading panel
In case the listview is embedded in another server control, you will need to append the id of that server control -->
<fieldset id="FiledSet1" style="width:435px;">
<legend>Customers</legend>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td>
<telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="RadListView1"
PageSize="5" Width="435px">
<Fields>
<telerik:RadDataPagerButtonField FieldType="FirstPrev" />
<telerik:RadDataPagerButtonField FieldType="Numeric" PageButtonCount="6" />
<telerik:RadDataPagerButtonField FieldType="NextLast" />
<telerik:RadDataPagerPageSizeField PageSizeText="Page size: " />
</Fields>
</telerik:RadDataPager>
</td>
</tr>
</table>
<asp:PlaceHolder ID="CustomersContainer" runat="server" />
<div style="clear: both" />
<br />
<br />
<table style="width: 100%;">
<tr>
<%--<td style="width: 25%;">
<asp:Button ID="btnInitInsert" runat="server" Text="Insert Customer" OnClick="btnInitInsert_Click" />
</td>--%>
<td style="text-align:center; width: 75%;">
<asp:Label ID="lblSort1" runat="server" Text="Sort by:" Style="padding-right: 5px;" />
<telerik:RadComboBox ID="ddListSort" runat="server" AutoPostBack="true">
<Items>
<telerik:RadComboBoxItem Text="-Select field to sort-" Value="" />
<telerik:RadComboBoxItem Text="Company name" Value="ArchitectName" />
<telerik:RadComboBoxItem Text="Sector" Value="Sector" />
</Items>
</telerik:RadComboBox>
</td>
</tr>
</table>
</div>
</fieldset>
</LayoutTemplate>
<ItemTemplate>
<!--The widths/heights of the fieldset/outer tables in the item/edit/insert templates should match to avoid wrapping or visual discrepancies
in the tiles layout-->
<fieldset style="float: left; width: 410px; height: 215px; margin-top:10PX;">
<legend style="font-weight:bold">
<%# Eval("ArchitectName")%></legend>
<table cellpadding="0" cellspacing="0" style="height: 100%;" width="370px">
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td style="font-weight:bold; width:25%">
Address:
</td>
<td style="width:auto; width:75%;">
<%#Eval("ArchitectAddress")%>
</td>
</tr>
<tr>
<td style="width:25%; font-weight:">
City:
</td>
<td>
<%# Eval("Contact1")%>
</td>
</tr>
<tr>
<td style="font-weight:bold">
Country:
</td>
<td>
<%# Eval("Contact2")%>
</td>
</tr>
<tr>
<td style="font-weight:bold">
Phone:
</td>
<td>
<%#Eval("Email_Id")%>
</td>
</tr>
<tr>
<td style="font-weight:bold">
Website:
</td>
<td>
<%#Eval("Website")%>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</fieldset>
</ItemTemplate>
<EmptyDataTemplate>
<fieldset style="width: 800px">
<legend>Customers</legend>No records for customers available.
</fieldset>
</EmptyDataTemplate>
</telerik:RadListView>
</asp:Panel>
</td>
</tr>
</table>
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:dbPortalConnectionString %>"
SelectCommand="SELECT * FROM [Architect]" >
</asp:SqlDataSource>
/div>
</form>
</body>
</html>
</asp:Content>
and this is my aspx.cs class
using System;
using System.Collections.Generic;
using System.Collections;
using System.Configuration;
using System.Web.Security;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Data;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace NoidaPortal
{
public partial class category : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
string s = Request.QueryString["cat"];
string s1 = Request.QueryString["sub"];
**I Just want to give here a SqlDataSource.Select command**
}
}
}
Could be possible because you haven't mentioned which is the codebehind for your page. Add this as the first line to your aspx page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="yourfile.aspx.cs" Inherits="YourProjectName.YourASPXPageName" %>
You have some stuff not allowed in your content placeholder because you're using a master. The reason you're not getting intellisense on your controls is because the page won't complile.
Remove these tags:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>
<form id="form1" runat="server">
Then try to compile your app. Fix any errors thrown by the compiler and recompile. Once the application is compilable, your intellisense should start working again.
Yes I found the solution here... I have to convert it to webApplication by right clicking on ProjectFolder and click on "Convert to Web Application". Than it's intellisense start working.
Related
Whenever I try to debug my content page of a master page, another webform which is not a content page runs. I even tried to change the URL after debugging but it didn't work. The URL gets changed automatically.
Please guide me, what could be the problem?
below code is the normal webform which automatically gets run
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Home.aspx.cs" Inherits="Library.Home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.style1
{
width: 100px;
}
.auto-style1 {
height: 30px;
}
.auto-style2 {
height: 25px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="head">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/digLib.jpg"
Height="95px" />
</div>
<div id="main"><div id="img">
<table class="style1">
<tr>
<td>
</td>
<td>
<asp:Image ID="Image2" runat="server" ImageUrl="~/Images/lib.jpg"
Height="314px"
style="margin-left: 94px" Width="561px" />
</td>
</tr>
</table>
</div>
<div id="login">
<table class="tbl">
<tr>
<td class="tblhead" colspan="2">
Login Area</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Label ID="lbl" runat="server" Font-Size="11px"
ForeColor="Red"></asp:Label>
</td>
</tr>
<tr>
<td class="auto-style1">
UserName :</td>
<td class="auto-style1">
<asp:TextBox ID="txtName" runat="server" CssClass="txt">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txtName" ErrorMessage="!!!"
ForeColor="Red"
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="lbl">
Password :
</td>
<td>
<asp:TextBox ID="txtPass" runat="server" CssClass="txt"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="txtPass" ErrorMessage="!!!"
ForeColor="Red"
SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style2">
</td>
<td class="auto-style2">
<asp:RadioButton ID="rdolibrary" runat="server"
Checked="True"
ForeColor="Green" GroupName="a" Text="Librarian" />
<asp:RadioButton ID="rdosudent" runat="server" ForeColor="Green"
GroupName="a"
Text="Student" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnLogin" runat="server" CssClass="btn"
Text="Login"
Width="80px" Font-Size="10pt" OnClick="btnLogin_Click1"
OnClientClick="btnLogin" />
</td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
below code is content page of a master page
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master"
AutoEventWireup="true" CodeBehind="AdminPage.aspx.cs"
Inherits="Library.WebForm2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<asp:Image runat="server" ID="img" ImageUrl="~/Images/lib.jpg" Height="100%"
Width="100%" />
</asp:Content>
below is the master page
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs"
Inherits="Library.Site" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div id="head">
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/digLib.jpg"
Width="500px" Height="100px" />
</div><div id="main"><div id="menu">
<table style="width:100%">
<tr>
<td class="tblhead">
welcome
</td>
</tr>
<tr>
<td bgcolor="#FFA76C" style="text-align: center">
<asp:Label ID="lblname" runat="server" ForeColor="#666666">
</asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button11" runat="server" CssClass="btnmenu"
Text="ADD PUBLICATION"
PostBackUrl="~/Publication.aspx"
CausesValidation="False"
/>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" CssClass="btnmenu"
Text="ADD BOOK"
PostBackUrl="~/Addbook.aspx" CausesValidation="False" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button2" runat="server" CssClass="btnmenu"
Text="BOOK Report"
CausesValidation="False" PostBackUrl="~/bookreport.aspx"
/>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button3" runat="server" CssClass="btnmenu"
Text="ADD Branch"
PostBackUrl="~/Addbranch.aspx" CausesValidation="False"
/>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button4" runat="server" CssClass="btnmenu"
Text="ADD Student"
PostBackUrl="~/AddStudent.aspx" CausesValidation="False"
/>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button5" runat="server" CssClass="btnmenu"
Text="Student Report" CausesValidation="False"
PostBackUrl="~/Studenteport.aspx" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button6" runat="server" CssClass="btnmenu"
Text="Issue Book"
CausesValidation="False" PostBackUrl="~/BookIssue.aspx"
/>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button7" runat="server" CssClass="btnmenu"
Text="Issue Report" CausesValidation="False"
PostBackUrl="~/Issuereport.aspx" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button8" runat="server" CssClass="btnmenu"
Text="Return Book"
CausesValidation="False" PostBackUrl="~/BookReturn.aspx" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button9" runat="server" CssClass="btnmenu"
Text="Panalty"
CausesValidation="False" PostBackUrl="~/Panalty.aspx" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button10" runat="server" CssClass="btnmenu"
Text="LogOut"
CausesValidation="False" onclick="Button10_Click" />
</td>
</tr>
</table>
</div><div id="detail"> <asp:ContentPlaceHolder
id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder></div></div>
</form>
</body>
</html>
I am trying to hide and show text boxes by radio button using jquery. I can show and hide text boxes but the error is I have a drop-down list. When I select drop-down value the page getting refreshed. After page refresh I am unable to do hiding and showing of text boxes. I have update panel for ajax. Why I am unable to hide and show text boxes after page refresh? Here is my source code. Please help me.
<%# Page Title="" Language="C#" MasterPageFile="~/Home.Master" AutoEventWireup="true" CodeBehind="ExperienceADD.aspx.cs" Inherits="Manjilas.WebForm31"%>
<%# Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" tagPrefix="ajax" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<head>
<script src="Scripts2/jquery-1.7-vsdoc.js"></script>
<script src="Scripts2/jquery-1.7.js"></script>
<script src="Scripts2/jquery-1.7.min.js"></script>
<script type="text/javascript">
$(function () {
$('input[name="type"]').on('click', function () {
if ($(this).val() == 'Experienced') {
$('#txtcomp').Show();
$('#txtfrom').Show();
$('#txtto').Show();
} else {
$('#txtcomp').hide();
$('#txtcomp').hide();
$('#txtfrom').hide();
$('#txtto').hide();
}
});
});
</script>
</head>
<div class="container-fluid">
<div class="row-fluid">
<div class="well span5 center login-box">
<div class="alert alert-info">
<b><font size="4">ADD EXPERIENCE DETAILS</font></b>
</div>
<form id="form1" runat="server">
<asp:UpdatePanel ID="updatepanel1" runat="server"><ContentTemplate>
<div>
<ajaxToolkit:ToolkitScriptManager runat="server">
</ajaxToolkit:ToolkitScriptManager>
<asp:UpdatePanel ID="updatepanel2" runat="server"></asp:UpdatePanel>
<fieldset>
<table class="ui-accordion">
<tr>
<td align="left" class="style2">
MachID</td>
<td align="left">
<%-- <div class="input-prepend" title="Select Country Name">--%>
<asp:DropDownList ID="ddid" runat="server" AutoPostBack="True"
onselectedindexchanged="ddid_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="left" class="style2">
<asp:Label ID="Empcode" runat="server" Text="EmpCode"></asp:Label>
<td align="left">
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="left" class="style2">
</td>
<td align="left">
<input type="radio" name="type" value="Fresher" />Fresher
<input type="radio" name="type" value="Experienced" />Experienced
</td>
</tr>
<tr>
<td align="left" class="style2">
Company</td>
<td align="left">
<div class="input-prepend" title="Autogenerated District ID" data-rel="tooltip">
<asp:TextBox ID="txtcomp" runat="server" TextMode="SingleLine"></asp:TextBox>
</td>
</tr>
<tr>
<td align="left" class="style2">
From Date</td>
<td align="left">
<div class="input-prepend" title="Enter District Name" data-rel="tooltip">
<asp:TextBox ID="txtfrom" runat="server" TextMode="SingleLine"></asp:TextBox>
<ajax:CalendarExtender ID="Calendarextender1" TargetControlID ="txtfrom" Format="dd/MM/yyyy" runat="server"></ajax:CalendarExtender>
</td>
</tr>
<tr>
<td align="left" class="style2">
To Date</td>
<td align="left">
<div class="input-prepend" title="Enter District Name" data-rel="tooltip">
<asp:TextBox ID="txtto" runat="server" TextMode="SingleLine"></asp:TextBox>
<ajax:CalendarExtender ID="Calendarextender2" TargetControlID ="txtto" Format="dd/MM/yyyy" runat="server"></ajax:CalendarExtender>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td align="left">
<asp:Button ID="Button1" class="btn-primary" runat="server" Text="Add"
Height="36px" Width="74px" onclick="Button1_Click" />
<asp:Button ID="Button2" class="btn-primary" runat="server" Text="Cancel"
Height="36px" Width="74px" PostBackUrl="~/districtDetails.aspx" />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td align="left">
<asp:Label ID="Label2" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</fieldset>
</form>
</div><!--/span-->
</div><!--/row-->
</div>
</div>
</asp:Content>
It's because you're using an UpdatePanel, it will refresh everything inside it's <ContentTemplate>, which in your case has input[name="type"] inside it.
Because it's refreshed, the on('click', function() { isn't binding the current radiobutton with the name="type" anymore, thus make the click never triggered after you select one item inside the dropdown, what you need is to wrap the UpdatePanel only for things that you want to be refreshed or changed only, like this for your case:
<asp:UpdatePanel ID="updatepanel1" runat="server">
<ContentTemplate>
<tr>
<td align="left" class="style2">
MachID
</td>
<td align="left">
<asp:DropDownList ID="ddid" runat="server" AutoPostBack="True"
onselectedindexchanged="ddid_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="left" class="style2">
<asp:Label ID="Empcode" runat="server" Text="EmpCode"></asp:Label>
</td>
<td align="left">
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
Other Way
Use the jQuery on click selector, you just need to change
$('input[name="type"]').on('click', function () {
if ($(this).val() == 'Experienced') {
$('#txtcomp').show();
$('#txtfrom').show();
$('#txtto').show();
}
too
$('.ui-accordion').on('click', 'input[name="type"]', function () {
if ($(this).val() == 'Experienced') {
$('#txtcomp').show();
$('#txtfrom').show();
$('#txtto').show();
}
The show function is k senstive. Try this:
$('#txtcomp,#txtfrom,#txtto').show();
I have added DropDownList1 in Default.aspx page my ASP.Net project, and I have the below code in Default.cs:
if(DropDownList1.SelectedItem.ToString()=="")
I got this error:
Error 2 The name 'DropDownList1' does not exist in the current context
Edit:
In *.cs:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string username = Login1.UserName;
string pwd = Login1.Password;
var connstring = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; ;
var conn = new SqlConnection(connstring);
conn.Open();
SqlCommand command;
if(DropDownList1.SelectedItem.ToString()=="")
command = new SqlCommand("Select [ID] from [Inspector] WHERE [ID] =" + username + " AND [Password] ='" + pwd + "';", conn);
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{
if (dr[0].ToString() == username)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("MainInspector.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}
}
In *.aspx:
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent" >
<style type="text/css">
.style1
{
height: 26px;
}
</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent" >
<h2>
الصفحة الرئيسية</h2>
<p>
الرجاء تسجيل الدخول:</p>
<p>
<asp:Login ID="Login1" runat="server"
FailureText="لم يتم تسجيل دخولك، الرجاء المحاولة ثانية."
LoginButtonText="تسجيل الدخول" onauthenticate="Login1_Authenticate"
PasswordLabelText="كلمة المرور:" RememberMeText="تذكرني في المرات القادمة"
TitleText="نسترعي إنتباهك أن كلمة المرور حساسة لحالة الأحرف"
UserNameLabelText="رقم الهوية:">
<LayoutTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">
<tr>
<td>
<table cellpadding="0">
<tr>
<td align="center" colspan="2">
نسترعي إنتباهك أن كلمة المرور حساسة لحالة الأحرف</td>
</tr>
<tr dir="rtl">
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">رقم الهوية:</asp:Label>
</td>
<td>
<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"
ControlToValidate="UserName" ErrorMessage="User Name is required."
ToolTip="User Name is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style1">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">كلمة المرور:</asp:Label>
</td>
<td class="style1">
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"
ControlToValidate="Password" ErrorMessage="Password is required."
ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td colspan="2">
تسجيل الدخول بوصفك:<br />
<asp:CheckBox ID="RememberMe" runat="server" Text="تذكرني في المرات القادمة" />
<br />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
<br />
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="LoginButton" runat="server" CommandName="Login"
Text="تسجيل الدخول" ValidationGroup="Login1" />
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>فاحص</asp:ListItem>
<asp:ListItem>مُدرب</asp:ListItem>
<asp:ListItem>مُتدرب</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
</p>
</asp:Content>
You need to check your markup to confirm that the ID matches i.e.
<asp:DropDownList id="DropDownList1".....
If it is a web application the designer.cs file could be messed up as this has the reference within it.
Something like this:
protected global::System.Web.UI.WebControls.DropDownList DropDownList1;
If it is missing try adding the above.
Such errors might appear when the markup in the .aspx page (or .ascx control) is not well formed. In cases where the markup is bad, when you add a new control its declaration is not added in the designer file and leads to this error.
If this is the case, one common trick to fix this is to cut and paste the markup of the control. This way you re-add the control and make Visual Studio to re-add the declaration of the control in the designer file.
DropDownList1 does not exist in the current context
The solution for me was to place the DropDownList outside of of the LoginView.
Try moving the DropDownList to another section of your page and see if this works.
I want to add controls dynamically
Code:
.aspx
<body>
<form id="form1" runat="server">
<asp:Label ID="lbl1" Text="Personal Information" Font-Size="Large" ForeColor="White" runat="server" Width="854px" BackColor="SteelBlue" style="margin-top: 0px" Height="60px"> </asp:Label>
<div id="div1" runat="server">
<asp:Panel ID="panelPersonal" runat="server">
<div id="divreg" runat="server">
<table id="tbl" runat="server">
<tr>
<td class="style8"> Visa Number:</td>
<td class="style20"> <asp:TextBox ID="txtUser" Width="160px" runat="server"/></td>
<td class="style22"> Country Name:</td>
<td class="style23"> <asp:DropDownList ID="dropCountry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td class="style22"> Type of Visa:</td>
<td class="style23"> <asp:DropDownList ID="dropVisa" Width="165px" runat="server"> </asp:DropDownList></td>
<td class="style22"> Type of Entry:</td>
<td class="style23"> <asp:DropDownList ID="dropEntry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td class="style8"> Expiry Date</td>
<td class="style20">
<%--<BDP:BasicDatePicker ID="BasicDatePicker4" runat="server" onselectionchanged="BasicDatePicker2_SelectionChanged" AutoPostBack="True" />--%>
</td>
</tr>
</table>
</div>
</asp:Panel>
<asp:Button ID="addnewtext" runat="server" Text="Add" onclick="addnewtext_Click" width="76px" />
</div>
</form>
Here I am using User control
.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="AddVisaControl.ascx.cs" EnableViewState="false" Inherits="Pyramid.AddVisaControl" %>
<div id="divreg" runat="server">
<table id="tbl" runat="server">
<tr>
<td> Visa Number:</td>
<td><asp:TextBox ID="txtUser" Width="160px" runat="server"/></td>
<td> Country Name:</td>
<td><asp:DropDownList ID="dropCountry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td> Type of Visa:</td>
<td><asp:DropDownList ID="dropVisa" Width="165px" runat="server"></asp:DropDownList></td>
<td> Type of Entry:</td>
<td><asp:DropDownList ID="dropEntry" Width="165px" runat="server"></asp:DropDownList></td>
</tr>
<tr>
<td> Expiry Date</td>
<td>
</td>
</tr>
</table>
</div>
.aspx.cs
Here is the problem If I click add button one row is added successfully but when I close and open again previously added rows also coming.
I think the problem is static int i = 0;
Any other way is there?
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
static int i = 0;
protected void addnewtext_Click(object sender, EventArgs e)
{
i++;
for (int j = 0; j <= i; j++)
{
AddVisaControl ac = (AddVisaControl)Page.LoadControl("AddVisaControl.ascx");
PlaceHolder1.Controls.Add(ac);
PlaceHolder1.Controls.Add(new LiteralControl("<BR>"));
}
}
This is what I am getting
This is what I want, Like below image I want to do
Any ideas? Thanks in advance
can you use a repeater /gridview control in the place of place holder control ,i think that is the best method for your situvation
I recommend this solution. It is different from the code you are using but still very easy.
You can use a Repeater control
<asp:Repeater ID="rpt1" runat="server">
<ItemTemplate>
user control code goes here but first put it in a div(example id - div1) with `style="display:none"`
</ItemTemplate>
</asp:Repeater>
on the server side you do this
rpt1.DataSource = Utils.GetRptTable(4); // will add the code 4 times but it will not be visible
rpt1.DataBind();
Later in javascript on the page you can find the first div with id div1 that has style - display:none and show it. That way you will show the next "row" with fields.
Edit 1
If you can add all your fields in the user control in a single <tr> you don't need a div with style= display:none. You will just have to add this class="GridBody" to your <tbody> - like: <tbody class="GridBody">
Then you do this to the row:
<tr class="GridRow" id="row1" style="display: none">
...
</tr>
and the javascript to show the row is:
function addRow() {
var body = $(".GridBody");
var indexOfNextRow = $('tr[class="GridRow"][hidden="false"]').length;
var tr = $(".GridBody tr")[indexOfNextRow];
tr.style.display = 'table-row';
tr.setAttribute('hidden', 'false');
}
I have a small page with 3 drop down list and text box.
my goal is to select a value in every one of the drop down boxes (or any combination) and after post back to set the selected value with the value from last search.
one of the problems is that 1. after every select in IE the page is doing post back(obviously)
and even when a added the attribute for enable view state the drop down list does not retain the selected value.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="QSerch.aspx.cs" Inherits="QSerch"
EnableViewState="true" EnableEventValidation="true" EnableViewStateMac="true"%>
<%# Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.ddlstl
{
font-size: 13px;
font-family: Arial;
}
#Iframe1
{
height: 700px;
width: 540px;
}
.style2
{
width: 243px;
}
</style>
</head>
<body dir="rtl">
<form id="form1" runat="server" enableviewstate="true">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="True"
EnablePartialRendering="true" LoadScriptsBeforeUI="false" ScriptMode="Release">
</asp:ScriptManager>
<div style="float: right; width: 28px;">
</div>
<div style="text-align: right; float: right;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table border="0">
<tr>
<td style="width: 170px;">
<asp:DropDownList ID="ddlMec" runat="server" AutoPostBack="True" CssClass="ddlstl"
Height="22px" Width="160px" EnableViewState="true" OnSelectedIndexChanged="ddlMec_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 20px;">
<asp:DropDownList ID="ddlTMec" runat="server" AutoPostBack="True" CssClass="ddlstl"
Height="22px" Width="160px" OnSelectedIndexChanged="ddlTMec_SelectedIndexChanged"
EnableViewState="true">
<asp:ListItem Value="-1">בחר תפקיד</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 170px;">
<asp:DropDownList ID="ddlArea" runat="server" AutoPostBack="True" CssClass="ddlstl"
DataSourceID="adsArea" DataTextField="name_area" DataValueField="id_area" Height="22px"
Width="160px" OnSelectedIndexChanged="ddlArea_SelectedIndexChanged" AppendDataBoundItems="true"
EnableViewState="true">
<asp:ListItem Value="-1" Text="בחר איזור"></asp:ListItem>
</asp:DropDownList>
<asp:AccessDataSource ID="adsArea" runat="server" DataFile="~/App_Data/Adam.mdb"
SelectCommand="SELECT [id_area], [name_area] FROM [table_area] ORDER BY [name_area]">
</asp:AccessDataSource>
</td>
</tr>
<tr>
<td>
<asp:TextBox runat="server" Text="חיפוש חופשי" ID="txtFreeText" Style="font-size: 12px;
height: 15px; width: 151px" />
<%--<input type="text" value="חיפוש חופשי" onfocus="deleteFreeText()" id="FreeText" name="FreeText"
style="font-size: 12px; height: 15px; width: 151px" runat="server" />--%>
<br />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" RenderMode="Inline" UpdateMode="Conditional">
<ContentTemplate>
<iframe id="Iframe1" runat="server" frameborder="0" name="Iframe1" scrolling="no"
width="360px" src="" style="overflow: auto"></iframe>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
protected void Page_Load(object sender, EventArgs e)
{
TextBox tb = (TextBox)FindControl("txtFreeText");
tb.Attributes.Add("onfocus", "this.value = ''");
if (!Page.IsPostBack)
{
LoadProffesion();
}
}
First two dropdowns, (id=ddlMec & id=ddlTMec) doesnt have any data asoociated to it. hope it will be dat bound during page load.
Assuming that you must be having problems with the 3rd dropdown, (id:ddlArea) it could be due to the fact that you are using datasource control to bind data. so everytime when page loads, it repopulates data and the selected item is lost.
To tideover this issue, please try binding the dropdownlist on page load and prevent overwriting by controlling it with the help of Page.IsPostBacK property.
Just remove the AutoPostBack="True" from tag.
there is no need of AutoPostBack for DropDownList.