I am using VS2005 C# ASP.NET.
I have a .aspx page with a script for user user membership management.
However, when I tried to implement Masterpage to my .aspx page, I received an error which says
Content controls have to be top-level controls in a content page or a nested master page that references a master page.
I have correctly referenced to my masterpage and I do not know where have I gone wrong.
Need help in pointing out where have I gone wrong in my .aspx page.
Thank you
Below is my code for my .aspx and masterpage:
.ASPX:
<%# Page Language="C#" MasterPageFile="~/MainPage.master"%>
<%# Import Namespace="System.Web.Security" %>
<%# Import Namespace="System.Web.UI" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" >
<script Runat="Server">
string[] rolesArray;
MembershipUserCollection users;
string[] usersInRole;
public void Page_Load()
{
Msg.Text = "";
if (!IsPostBack)
{
// Bind roles to ListBox.
rolesArray = Roles.GetAllRoles();
RolesListBox.DataSource = rolesArray;
RolesListBox.DataBind();
// Bind users to ListBox.
users = Membership.GetAllUsers();
UsersListBox.DataSource = users;
UsersListBox.DataBind();
}
if (RolesListBox.SelectedItem != null)
{
// Show users in role. Bind user list to GridView.
usersInRole = Roles.GetUsersInRole(RolesListBox.SelectedItem.Value);
UsersInRoleGrid.DataSource = usersInRole;
UsersInRoleGrid.DataBind();
}
}
public void AddUsers_OnClick(object sender, EventArgs args)
{
// Verify that a role is selected.
if (RolesListBox.SelectedItem == null)
{
Msg.Text = "Please select a role.";
return;
}
// Verify that at least one user is selected.
if (UsersListBox.SelectedItem == null)
{
Msg.Text = "Please select one or more users.";
return;
}
// Create list of users to be added to the selected role.
string[] newusers = new string[UsersListBox.GetSelectedIndices().Length];
for (int i = 0; i < newusers.Length; i++)
{
newusers[i] = UsersListBox.Items[UsersListBox.GetSelectedIndices()[i]].Value;
}
// Add the users to the selected role.
try
{
Roles.AddUsersToRole(newusers, RolesListBox.SelectedItem.Value);
// Re-bind users in role to GridView.
usersInRole = Roles.GetUsersInRole(RolesListBox.SelectedItem.Value);
UsersInRoleGrid.DataSource = usersInRole;
UsersInRoleGrid.DataBind();
Msg.Text = "User(s) added to role: " + RolesListBox.SelectedItem.Text;
return;
}
catch (Exception e)
{
Msg.Text = e.Message;
}
}
public void UsersInRoleGrid_RemoveFromRole(object sender, GridViewCommandEventArgs args)
{
// Get the selected user name to remove.
int index = Convert.ToInt32(args.CommandArgument);
string username = ((DataBoundLiteralControl)UsersInRoleGrid.Rows[index].Cells[0].Controls[0]).Text;
// Remove the user from the selected role.
try
{
Roles.RemoveUserFromRole(username, RolesListBox.SelectedItem.Value);
}
catch (Exception e)
{
Msg.Text = "An exception of type " + e.GetType().ToString() +
" was encountered removing the user from the role.";
}
// Re-bind users in role to GridView.
usersInRole = Roles.GetUsersInRole(RolesListBox.SelectedItem.Value);
UsersInRoleGrid.DataSource = usersInRole;
UsersInRoleGrid.DataBind();
Msg.Text = "User(s) removed from role: " + RolesListBox.SelectedItem.Text;
return;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Role Membership</title>
</head>
<body>
<form runat="server" id="PageForm">
<font face="helvetica" size="6" color="#455c75"><strong>Role Membership</strong></font><font face="helvetica" size="5" color="#455c75"><strong> Management</strong></font><br /><asp:Label ID="Msg" ForeColor="maroon" runat="server" /><br />
<br />
<table cellpadding="3" border="0">
<tr>
<td valign="top" style="width: 117px; height: 145px;">
<font face="helvetica" size="3" color="#455c75"><strong>Roles:</strong></font></td>
<td valign="top" style="height: 145px; width: 265px;">
<asp:ListBox ID="RolesListBox" runat="server" Rows="8" AutoPostBack="true" /></td>
<td valign="top" style="height: 145px">
<font face="helvetica" size="3" color="#455c75"><strong>Users:</strong></font></td>
<td valign="top" style="height: 145px">
<asp:ListBox ID="UsersListBox" DataTextField="Username" Rows="8" SelectionMode="Multiple"
runat="server" />
<br />
<asp:Button Text="Add User(s) to Role" ID="AddUsersButton" runat="server" OnClick="AddUsers_OnClick" /></td>
<td valign="top" style="height: 145px">
</td>
</tr>
<tr>
<td valign="top" style="width: 117px">
<font face="helvetica" size="3" color="#455c75"><strong>Users in Role:</strong></font></td>
<td valign="top" style="width: 265px">
<asp:GridView runat="server" CellPadding="4" ID="UsersInRoleGrid" AutoGenerateColumns="False"
GridLines="Horizontal" OnRowCommand="UsersInRoleGrid_RemoveFromRole" ForeColor="#333333">
<HeaderStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
<Columns>
<asp:TemplateField HeaderText="User Name" >
<ItemTemplate>
<%# Container.DataItem.ToString() %>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField Text="Remove From Role" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>
</asp:Content>
Masterpage:
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MainPage.master.cs" Inherits="MainPage" %>
<!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 id="Head1" runat="server">
<title>RM</title>
<link href="Styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<form id="form1" runat="server">
<div id="header" style="height: 2.7em">
<span class="title">Role Management</span>
<span class="breadcrumb">
<asp:SiteMapPath ID="SiteMapPath1" runat="server">
</asp:SiteMapPath>
</span>
</div>
<div id="content">
<asp:contentplaceholder id="MainContent"
runat="server">
<!-- Page-specific content will go here... -->
</asp:contentplaceholder>
<br />
</div>
<div id="navigation" style="top: 4.19em; left: 0.51em;">
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="260px">
<font size="2">You are logged in as </font>
<asp:LoginName ID="LoginName1" runat="server" Font-Bold="False" Font-Underline="False" ForeColor="RoyalBlue" Font-Italic="False" />
<br />
<asp:LinkButton ID="Logout" runat="server" Font-Bold="True" Font-Underline="True"
OnClick="Logout_Click" Font-Size="Smaller" ToolTip="Logout">Logout</asp:LinkButton></asp:Panel>
<ul>
<li>
<asp:HyperLink runat="server" ID="lnkHome"
NavigateUrl="/SoD/Common/Default.aspx">Home</asp:HyperLink>
<asp:Repeater runat="server" ID="menu" DataSourceID="SiteMapDataSource1" EnableViewState="False">
<ItemTemplate>
<li>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("Url") %>'>
<%# Eval("Title") %></asp:HyperLink>
<asp:Repeater ID="Repeater1" runat="server"
DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>'>
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl='<%# Eval("Url") %>'>
<%# Eval("Title") %></asp:HyperLink>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>
</li>
</ul>
</div>
<asp:SiteMapDataSource ID="SiteMapDataSource1"
runat="server" ShowStartingNode="false" />
</form>
</div>
</body>
</html>
The <asp:Content> misses runat="server"
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server" >
One more thing remove the following tags from the .aspx file
<head> , <form>, <body>, and <html> because these tags are inherited from the Master Page
Related
Okay, I have searched and searched, and methods that work for others don't seem to be working for me. I am trying to get AJAX's autocomplete to work but I have had no luck. Eventually, I want a textbox with autocomplete, pulling data from a sqldatasource, but first, I just want it to work. So, I have tried a simple implementation that I found on this website. The individual who used this code got it to work using this code, but my textbox functions just like an ordinary textbox (with no autocomplete features). I am fairly new to web dev and would appreciate any assistance. Thanks.
UPDATE:
Okay...I tried making a new, simple, webpage and tried to do the autocomplete thing again. I get this bizarre result (Single characters that make no sense):
Incorrect Autocomplete Image
aspx code
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
string[] results = { "test", "test", "test" };
return results;
}
cs. code
<asp:Label ID="FieldLabel" Text="Label:" runat="server"></asp:Label>
<asp:TextBox ID="InputField" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
ID="Autocompleter"
TargetControlID="InputField"
ServiceMethod="GetCompletionList"
ServicePath="~/BatchReleaseStatus.aspx"
MinimumPrefixLength="1"
CompletionInterval="1000"
runat="server">
</ajaxToolkit:AutoCompleteExtender>
Site.Master
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="CrownLabsDbFrontEnd.SiteMaster" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title><%: Page.Title %> - Crown Labs Quality Database</title>
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>
<webopt:bundlereference runat="server" path="~/Content/css" />
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<style type="text/css">
.auto-style1 {
width: 131px;
height: 91px;
}
</style>
</head>
<body>
<form runat="server">
<asp:ScriptManager runat="server" EnablePageMethods="true" EnableScriptGlobalization="true">
<Scripts>
<%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
<%--Framework Scripts--%>
<asp:ScriptReference Name="MsAjaxBundle" />
<asp:ScriptReference Name="jquery" />
<asp:ScriptReference Name="bootstrap" />
<asp:ScriptReference Name="respond" />
<asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
<asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
<asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
<asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
<asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
<asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
<asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
<asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
<asp:ScriptReference Name="WebFormsBundle" />
<%--Site Scripts--%>
</Scripts>
</asp:ScriptManager>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" runat="server" href="~/"><img alt="Crown Labs Logo" class="auto-style1" src="file:///C:/Users/bcampbell/Pictures/logo_crown.gif" /></a> </div>
<div class="navbar-collapse collapse" style="padding-top:50px">
<ul class="nav navbar-nav">
<li><a runat="server" href="~/">Home</a></li>
<li><a runat="server" href="~/BatchReleaseStatus">Batch Release Status</a></li>
<li><a runat="server" href="~/CAPA">CAPA</a></li>
<li><a runat="server" href="~/Investigations">Investigations</a></li>
<li><a runat="server" href="~/Validations">Validations</a></li>
<li><a runat="server" href="~/Administration">Administration</a></li>
</ul>
<asp:LoginView runat="server" ViewStateMode="Disabled">
<AnonymousTemplate>
<ul class="nav navbar-nav navbar-right">
<li><a runat="server" href="~/Account/Register">Register</a></li>
<li><a runat="server" href="~/Account/Login">Log in</a></li>
</ul>
</AnonymousTemplate>
<LoggedInTemplate>
<ul class="nav navbar-nav navbar-right">
<li><a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName() %> !</a></li>
<li>
<asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" />
</li>
</ul>
</LoggedInTemplate>
</asp:LoginView>
</div>
</div>
</div>
<div class="container body-content">
<hr />
<footer>
<p>© <%: DateTime.Now.Year %> - My ASP.NET Application<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</footer>
</div>
</form>
<script src="Scripts/currentClass.js"></script>
</body>
</html>
BatchReleaseStatus.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BatchReleaseStatus.aspx.cs" Inherits="CrownLabsDbFrontEnd.BatchReleaseStatus" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<p><%--The following <p>'s keep the content from going under the Master Header --%>
<p> <p>
<asp:Button ID="btnShow_ClientSide" runat="server"
Text="show client side" OnClientClick="return false" />
<asp:Button ID="btnShow_ServerSide" runat="server"
Text="show server side" OnClick="btnShow_ServerSide_Click" />
<ajaxToolKit:ModalPopupExtender ID="mdlPopup" runat="server"
TargetControlID="btnShow_ClientSide"
PopupControlID="pnlPopup" CancelControlID="btnHide_ClientSide"
BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlPopup" runat="server"
BackColor="#CCFFFF" BorderColor="#FF6699" style="text-align: left">
Batch Number:
<asp:TextBox ID="BatchNumTextBox" runat="server"></asp:TextBox>
Part:
<br />
<asp:Button ID="btnHide_ClientSide" runat="server"
Text="hide client side" OnClientClick="return false" OnClick="btnHide_ClientSide_Click" />
<asp:Button ID="btnHide_ServerSide" runat="server"
Text="hide server side" OnClick="btnHide_ServerSide_Click" />
</asp:Panel>
<asp:Label ID="FieldLabel" Text="Label:" runat="server"></asp:Label>
<asp:TextBox ID="InputField" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender
ID="Autocompleter"
TargetControlID="InputField"
ServiceMethod="GetCompletionList"
ServicePath="~/BatchReleaseStatus.aspx"
MinimumPrefixLength="1"
CompletionInterval="1000"
runat="server">
</ajaxToolkit:AutoCompleteExtender>
<p>
<asp:SqlDataSource ID="BatchReleaseData" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" SelectCommand=<%# ViewState["stringInViewState"] %>></asp:SqlDataSource>
<%--Set up the stationary header for the primary GridView --%>
<div style =" background-color:navy;
height:30px;width:450px; margin-left:auto; margin-right:auto">
<table cellspacing="0" cellpadding = "0" border="0" id="tblHeader"
style="font-family:Arial;font-size:10pt;width:438px;color:white;
border-collapse:collapse;height:100%;">
<tr>
<%--Sets up the link buttons that will populate the header and allow sorting --%>
<td style ="width:165px;text-align:center">
<asp:LinkButton ID="MfgDatLnkBtn" runat="server" OnClick="MfgDatLnkBtn_Click" ForeColor="White">Manufacture Date</asp:LinkButton>
</td>
<td style ="width:140px;text-align:center">
<asp:LinkButton ID="BatchLnkBtn" runat="server" OnPreRender="LinkButtons_PreRender" OnClick="BatchLnkBtnClck">Batch ID</asp:LinkButton>
</td>
<td style ="width:135px;text-align:center">
<asp:LinkButton ID="DescriptionLnkBtn" runat="server" OnPreRender="LinkButtons_PreRender" OnClick="DescriptionLnkBtn_Click">Description</asp:LinkButton>
</td>
<td style ="width:140px;text-align:center">
<asp:LinkButton ID="BaseLnkBtn" runat="server" OnPreRender="LinkButtons_PreRender" OnClick="BaseLnkBtn_Click">Base</asp:LinkButton>
</td>
</tr>
</table>
</div>
<div style="margin-left:auto; margin-right:auto; width:450px; overflow:auto; height:450px; border:solid">
<table class="nav-justified">
<tr>
<td style="text-align: center">
<div style="margin-left:auto; margin-right:auto">
<asp:GridView ID="BatchReleaseGV" DataSourceId="BatchReleaseData" DataKeyNames="Mfg_Date" AutoGenerateColumns="false" ShowHeader="false"
runat="server" OnSelectedIndexChanged="BatchReleaseGV_SelectedIndexChanged" OnRowDataBound="BatchReleaseGV_RowDataBound">
<Columns>
<asp:BoundField ItemStyle-Width = "150px" DataField="Mfg_Date" HeaderText="Manufacture Date" DataFormatString="{0:MM/dd/yyyy }" HtmlEncode=false >
<ItemStyle Font-Size="Large" />
</asp:BoundField>
<asp:BoundField ItemStyle-Width = "150px" DataField="Batch" HeaderText="Batch ID"
FooterText="">
<FooterStyle CssClass="FooterStyle" />
</asp:BoundField >
<asp:BoundField ItemStyle-Width = "150px" DataField="Product" HeaderText="Description" />
<asp:BoundField ItemStyle-Width = "150px" DataField="Base" HeaderText="Base (if applicable)" />
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</table>
</div>
<p>
<asp:SqlDataSource ID="BatchReleaseDataMfgDateOnly" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" SelectCommand="SELECT DISTINCT CONVERT(date,[Mfg Date]) AS Mfg_Date FROM [Batch Info] ORDER BY [Mfg_Date] DESC"></asp:SqlDataSource>
<asp:SqlDataSource ID="BatchReleaseDataBatchOnly" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" SelectCommand="SELECT DISTINCT [Batch] FROM [Batch Info] ORDER BY [Batch]"></asp:SqlDataSource>
<asp:SqlDataSource ID="BatchReleaseDataProductOnly" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" SelectCommand="SELECT DISTINCT [Product] FROM [Batch Info] ORDER BY [Product]"></asp:SqlDataSource>
<asp:SqlDataSource ID="BatchReleaseDataBaseOnly" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" SelectCommand="SELECT DISTINCT [Base] FROM [Batch Info] ORDER BY [Base]"></asp:SqlDataSource>
</p>
<table class="nav-justified">
<tr>
<td class="text-right">Manufacturing Date:
</td>
<td class="text-left">
<asp:TextBox ID="MfgDateTxtBx" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="MfgDateTxtBx_CalendarExtender" runat="server" TargetControlID="MfgDateTxtBx" />
<asp:RegularExpressionValidator ID="MfgDateValidator" runat="server" ControlToValidate="MfgDateTxtBx" ErrorMessage="Invalid Date Entered" ValidationExpression="^((0?[13578]|10|12)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[01]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1}))|(0?[2469]|11)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[0]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1})))$" Font-Bold="True" ForeColor="Red"></asp:RegularExpressionValidator>
</td>
<td> Batch ID:
<asp:DropDownList ID="BatchDropDown" runat="server" DataSourceID="BatchReleaseDataBatchOnly" DataValueField="Batch">
</asp:DropDownList>
</td>
<td> Description:
<asp:DropDownList ID="ProductDropDown" runat="server" DataSourceID="BatchReleaseDataProductOnly" DataValueField="Product">
</asp:DropDownList>
</td>
<td>Base: <asp:DropDownList ID="BaseDropDown" runat="server" DataSourceID="BatchReleaseDataBaseOnly" DataValueField="Base">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="text-right">To (Optional): </td>
<td style="text-align: left">
<asp:TextBox ID="DateRangeTxtBx" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="DateRangeTxtBx_CalendarExtender" runat="server" TargetControlID="DateRangeTxtBx" />
<asp:RegularExpressionValidator ID="MfgDateRangeValidator" runat="server" ControlToValidate="DateRangeTxtBx" ErrorMessage="Invalid Date Entered" ValidationExpression="^((0?[13578]|10|12)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[01]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1}))|(0?[2469]|11)(-|\/)(([1-9])|(0[1-9])|([12])([0-9]?)|(3[0]?))(-|\/)((19)([2-9])(\d{1})|(20)([01])(\d{1})|([8901])(\d{1})))$" Font-Bold="True" ForeColor="Red" Display="Dynamic"></asp:RegularExpressionValidator>
<asp:CompareValidator id="MfgDateRangeComparator" runat="server"
ControlToCompare="MfgDateTxtBx" cultureinvariantvalues="true"
display="Dynamic" enableclientscript="true"
ControlToValidate="DateRangeTxtBx"
ErrorMessage="Start date must be earlier than finish date"
type="Date" setfocusonerror="true" Operator="GreaterThanEqual"
text="Start date must be earlier than finish date" Font-Bold="True" ForeColor="Red"></asp:CompareValidator>
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="TextBox3_AutoCompleteExtender" runat="server" TargetControlID="TextBox3" MinimumPrefixLength="1" ServiceMethod="GetCompletionList" ServicePath="BatchReleaseStatus.aspx">
</ajaxToolkit:AutoCompleteExtender>
</td>
<td> </td>
<td> </td>
</tr>
</table>
<p>
<asp:Button ID="submitBtn" runat="server" OnClick="submitBtn_Click" Text="Submit" />
</p>
<p>
</p>
</asp:Content>
In order to use System.Web.Services.WebMethod in a codebehind file from an aspx Site, this method must be static. Also your scriptmanager need to have "EnablePageMethods=true" setted.
=> This approach is called PageMethods.
I think it's better to use WebApi instead of PageMethods, you can easily integerate this into your asp.net project. Here you will find a startpoint.
Getting started with Web-API
PageMethod-Test:
<script type="text/javascript">
function Test() {
PageMethods.Test(function(result){alert(result);});
}
[System.Web.Services.WebMethod]
public static string Test()
{
return "Hello StackOverflow";
}
Hello I have the following problem I tried and nothing , I can not recover my text box user control , the TexBox will use them in the EDIT POPUP
CONVENIO.ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="convenios.aspx.cs" Inherits="convenios5.convenios" %>
<%# Register TagPrefix="ModalPopup" TagName="detalle" Src="~/UserControls/Popup_conveniodetalle.ascx"%>
<%# Register TagPrefix="ModalPopup" TagName="editar" Src="~/UserControls/Popup_conveniomodificar.ascx"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<link href="Styles/GridStyle.css" rel="stylesheet" type="text/css" />
<%--<link href="Styles/bootstrap.css" rel="stylesheet" type="text/css" />--%>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>
<link href="http://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<%-- CERRAR DIALOG UI --%>
<script type="text/javascript">
function closeDialog() {
$("#divmodificar").dialog('close');
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div class="panel panel-default">
<div class="panel-heading">
<h3>:: CONVENIOS CLINICA CAYETANO ::</h3>
</div>
<div class="panel-body">
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table width="100%">
<tr id="trMessage" runat="server" visible="false">
<td>
<asp:Label ID="lblMessage" runat="server" Text="No hay datos que mostar"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="gridconvenios" runat="server" AllowPaging="true" PageSize="5"
CssClass="GridStyle" BorderColor="#cbcbcb" BorderStyle="solid" OnRowCommand="gridconvenios_RowCommand" OnPageIndexChanging="gridconvenios_PageIndexChanging"
BorderWidth="1" AutoGenerateColumns="false" DataKeyNames="COD_CONVENIO" width="100%">
<AlternatingRowStyle CssClass="GridStyle_AltRowStyle" />
<HeaderStyle CssClass="GridStyle_HeaderStyle" />
<RowStyle CssClass="GridStyle_RowStyle" />
<pagerstyle cssclass="GridStyle_pagination" />
<Columns>
<asp:TemplateField HeaderText="CODIGO">
<ItemStyle HorizontalAlign="Center" width="5%" />
<ItemTemplate>
<asp:LinkButton ID="cmddetalle" runat="server" CausesValidation="False" Text='<%# Eval("COD_CONVENIO") %>' CommandName="detalle" CommandArgument='<%# Eval("COD_CONVENIO") %>' ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ENTIDAD">
<ItemStyle width="20%" />
<ItemTemplate>
<asp:Label ID="lblRequiredDate" runat="server" Text='<%# Eval("DES_IAFA") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CONVENIO">
<ItemStyle HorizontalAlign="Center" width="10%" />
<ItemTemplate>
<asp:Label ID="lblShippedDate" runat="server" Text='<%# Eval("DES_CONVENIO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="INICIO">
<ItemStyle width="5%" />
<ItemTemplate>
<asp:Label ID="lblShipName" Text='<%# Eval("FEC_INI") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FIN">
<ItemStyle width="5%" />
<ItemTemplate>
<asp:Label ID="lblShipAddress" Text='<%# Eval("FEC_INI") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FACTOR">
<ItemStyle width="5%" />
<ItemTemplate>
<asp:Label ID="lblfactor" Text='<%# Eval("IMP_FACTORHON") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ESTADO">
<ItemStyle width="5%" />
<ItemTemplate>
<asp:Label ID="lblestado" Text='<%# Eval("EST_CONVENIO") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Center" width="5%" />
<ItemTemplate>
<asp:ImageButton ID="cmdEdit" CommandName="editar" CommandArgument='<%# Eval("COD_CONVENIO")%>' runat="server" ImageUrl="~/images/edit.gif" CausesValidation="False"></asp:ImageButton>
<asp:ImageButton ID="cmdDelete" CommandName="eliminar" CommandArgument='<%# Eval("COD_CONVENIO")%>' runat="server" ImageUrl="~/images/delete.gif" CausesValidation="False"></asp:ImageButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<div id="divmodificar" style="display:none;">
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<ModalPopup:editar ID="ucmodificar" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gridconvenios" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
</div>
</div>
</div>
</form>
</body>
</html>
CONVENIOS.ASPX.CS
protected void gridconvenios_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
string COD_CONVENIO = Convert.ToString(e.CommandArgument);
switch (e.CommandName.ToLower())
{
case "editar":
System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
sb1.Append("<script type='text/javascript'>");
sb1.Append(" $(\"#divmodificar\").dialog({");
sb1.Append(" title: \"EDITAR CONVENIO: " + COD_CONVENIO + "\",");
sb1.Append("position:'center', width:'auto', autoresize:true, modal:true,");
sb1.Append("open: function(type,data) {");
sb1.Append("$(this).parent().appendTo(\"form\");");
sb1.Append("}");
sb1.Append("});");
sb1.Append("</script>");
var ucmodificar1 = (convenios5.UserControls.Popup_conveniomodificar)ucmodificar;
ucmodificar1.BindOrderDetail(COD_CONVENIO);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ModalScript1", sb1.ToString(), false);
break;
}
}
CONVENIOEDITAR.ASCX
<asp:Panel ID="Panel1" runat="server">
<fieldset>
<legend>DATOS CONVENIO</legend>
<table width="100%">
<tr>
<td class="cabecera">CÓDIGO: </td>
<td class="texto"><asp:Textbox ID="Text1" runat ="server"></asp:Textbox></td>
</tr>
<tr>
<td class="cabecera">DESCRIPCIÓN: </td>
<td class="texto"><asp:Textbox ID="Text2" runat="server" Width="80%"></asp:Textbox></td>
</tr>
<tr>
<td class="cabecera">FACTOR: </td>
<td class="texto"><asp:Textbox ID="Text3" runat="server" Width="80%"></asp:Textbox></td>
</tr>
<tr>
<td class="cabecera">ESTADO: </td>
<td>
<p>
<asp:RadioButton ID="activo" runat="server" Text="Activo"/>
<asp:RadioButton ID="inactivo" runat="server" Text="Inactivo"/>
</p>
</td>
</tr>
<tr>
<td colspan="2" align="right">
CONVENIOEDITAR.ASCX (HERE PROBLEM)
protected void cmdAdd_Click(object sender, EventArgs e)
{
string VAR1 = this.Text1.Text;// THIS VAR1 IS NULL
}
I can not capture the value of VAR1 appears to me as NULL.
Please help me...
I would use the onClientClick property of the asp:LinkButton, and get the textbox value via jQuery
<asp:LinkButton> .. OnClientClick="GetText1Val();" </asp:LinkButton>
And the function:
<script language="javascript">
function GetText1Val() {
var Text1Value = $("#Text1").val();
alert(Text1Value);
}
</script>
I'm getting tihs error:
Cannot call method 'getElementsByTagName' of null.
Alert #1 pops up, alert #2 pops up, but obviously either the call to create gvHeader or the call to build headers fails and I never see alert #3.
I've also tried putting #<% before and after on "dummyHeader" and "th". I've tried "TH" as well.
Note, I'm trying to follow this suggestion. I have been unsuccessful in getting any help from the author or anyone else on that site.
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPages/Main.Master" AutoEventWireup="true" CodeBehind="CraigTest.aspx.cs" Inherits="OfficeIntranet.Forms.Purchasing.CraigTest" %>
<%# Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit,
Version=4.1.51116.0, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.tablesorter.js" type="text/javascript"></script>
<link href="../../Styles/StyleSheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$("#<%=gvOrderDetails.ClientID%>").tablesorter();
alert("Are we here 1?");
SetDefaultSortOrder();
alert("Are we here 4?");
});
function Sort(cell, sortOrder) {
var sorting = [[cell.cellIndex, sortOrder]];
$("#<%=gvOrderDetails.ClientID%>").trigger("sorton", [sorting]);
if (sortOrder == 0) {
sortOrder = 1;
cell.className = "sortDesc";
}
else {
sortOrder = 0;
cell.className = "sortAsc";
}
cell.setAttribute("onclick", "Sort(this, " + sortOrder + ")");
cell.onclick = function () { Sort(this, sortOrder); };
document.getElementById("container").scrollTop = 0;
}
function SetDefaultSortOrder() {
var gvHeader = document.getElementById("dummyHeader");
alert("Are we here 2?");
var headers = gvHeader.getElementsByTagName("th");
alert("Are we here 3?");
for (var i = 0; i < headers.length; i++) {
headers[i].setAttribute("onclick", "Sort(this, 1)");
headers[i].onclick = function () { Sort(this, 1); };
headers[i].className = "sortDesc";
}
}
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderBody" runat="server">
<asp:UpdatePanel ID="UpdatePanelSPA" runat="server" UpdateMode="Always">
<ContentTemplate>
<div id="headerE" runat="server" style="text-align: center; width: auto;">
<asp:Label ID="MainH" CssClass="headerText" runat="server">SPA Order Control</asp:Label>
<asp:Label ID="headVersion" CssClass="textarea" runat="server"></asp:Label>
</div>
<asp:Panel ID="PanelDetails" runat="server" Width="960px" Style="margin-left: 20px;" Visible="false">
<div class="container" id="DetailsSection">
<div>
<table class="tablesorter" id="dummyHeader" rules="all"; style="width:940px; height:25px; border-collapse:collapse">
<col style="width:78px" />
<col style="width:225px" />
<tr style="background-color: LightGrey; height:25px; font-weight:bold; border-width:1px; border-color:Gray"/>
<th scope="col">Item Code</th>
<th scope="col">Description</th>
</tr>
</table>
<div style="height:550px; width:942px; overflow:auto;">
<asp:GridView ID="gvOrderDetails" runat="server" ShowHeader="false"
AlternatingRowStyle-BackColor="#FAFAFA" Width="924px"
AutoGenerateColumns="False" AllowSorting="True" OnSorting="SortOrderDetails"
OnRowCommand="gvOrderDetails_RowCommand" EmptyDataText="No Data to Display"
DataKeyNames="STOREORDNUM" HeaderStyle-Height="22px"
onselectedindexchanged="gvOrderDetails_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF"/>
<FooterStyle BackColor="LightGray" Font-Bold="False" ForeColor="Black" />
<HeaderStyle BackColor="LightGray" Font-Bold="False" ForeColor="Black" BorderWidth="1px" BorderColor="Gray"/>
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" Height="22px"/>
<Columns>
<asp:BoundField DataField="ITMCD" HeaderText="Item Code" >
<ItemStyle CssClass="gvAlignCenter5pxR" Width="78px" />
</asp:BoundField>
<asp:BoundField DataField="DESC" HeaderText="Description" >
<ItemStyle CssClass="gvAlignLeft5pxR" Width="232px"/>
</asp:BoundField>
</Columns>
</asp:GridView>
</div>
</div>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
I have a master page and their is script manager with update panel inside it. . now i am trying to add update panel in content page without using script manager but it gives me an error:
The control with ID 'updpanel' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.
I know i can use only one instance of script manager, then i tried ScriptManagerProxy but it gives me the error that scriptMangerProxy requires script manager.
I also tried ajax:ToolScriptManager but it also gives the same results
So the question is how can make the update panel to work in content page..
Master Page:
<%# Master Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="SideMaster.master.cs" Inherits="SideMaster" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/jscript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#chit').scrollTop(1000000);
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="sidemenu">
<asp:SiteMapDataSource ID="topNav" runat="server" />
<asp:Menu ID="SideMenu" runat="server" DataSourceID="topNav" CssClass="SideMenu" StaticDisplayLevels="4"
Font-Bold="true" Font-Size="20" IncludeStyleBlock="true" >
<StaticMenuItemStyle VerticalPadding="5" BackColor="#670a0a" ForeColor="White" HorizontalPadding="5" />
<StaticSelectedStyle BackColor="White" ForeColor="#670a0a" />
</asp:Menu>
</div>
<div class="cont3" >
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="rightmenu">
<div class="newspan">
<asp:Repeater ID="RepNews" runat="server" >
<HeaderTemplate><div class="newsheadcont">News & Events</div></HeaderTemplate>
<ItemTemplate>
<div class="newstemp">
<hr />
# <%#Eval("News") %>
<asp:LinkButton ID="LinkNews" runat="server" CssClass="welcomeMore"></asp:LinkButton>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
<br /><br />
<div class="chatcont" style="margin-left:1%;">
<div class="chat">
<h2 class="chathead">Peoples Talking About </h2>
<asp:ScriptManager ID="scmang" runat="server"></asp:ScriptManager>
<%--<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>--%>
<script type="text/javascript">
var xPos, yPos;
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequestHandler);
function BeginRequestHandler(sender, args) {
xPos = $get('chit').scrollLeft;
yPos = $get('chit').scrollTop;
}
function EndRequestHandler(sender, args) {
$get('chit').scrollLeft = xPos;
$get('chit').scrollTop = yPos;
}
</script>
<asp:UpdatePanel ID="updPanelChat" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Panel ID="pan" runat="server">
<asp:ListView ID="ListChat" runat="server" >
<LayoutTemplate>
<div class="chattemp" style="width:250px; " id="chit" >
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</div>
</LayoutTemplate>
<ItemSeparatorTemplate><hr /></ItemSeparatorTemplate>
<EmptyDataTemplate>No Data Found</EmptyDataTemplate>
<ItemTemplate>
<div class="chatbox" >
<div class="chatpic" style="margin:18px 0px 0px 0px;" >
<asp:ImageButton ID="ImageChat" runat="server"
ToolTip='<%#Eval("UserName") %>'
ImageUrl='<%# "~/ShowImage.ashx?Name=" + Server.UrlEncode(Eval("UserName").ToString()) %>'
PostBackUrl='<%#"~/Profile/Profile.aspx?Name="+Eval("UserName") %>'
Width="50" Height="50" />
</div>
<div class="chatbubble" style="width:160px; margin:-50px 5px 5px 60px; float:left;">
<asp:Label ID="LabelChat" runat="server" Width="100" Height="50"><%#Eval("Body") %></asp:Label>
</div>
<div class="chatname" style="width:50px; border:none;" >
<asp:LinkButton ID="LinkUserName" runat="server"
PostBackUrl='<%#"~/Profile/Profile.aspx?Name="+Eval("UserName") %>'><%#Eval("UserName") %></asp:LinkButton>
</div>
</div>
</ItemTemplate>
</asp:ListView>
<asp:Timer ID="TimerUpdate" runat="server" Interval="20000"
ontick="TimerUpdate_Tick"></asp:Timer>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<div class="messagebox" style="width:250px; height:120px; border:none;">
<asp:TextBox ID="TextBoxMessage" runat="server" TextMode="MultiLine" Visible="false" Width="250" Height="80" MaxLength="500"></asp:TextBox>
<asp:Button ID="ButtonMessage" runat="server" Text="Comment"
onclick="ButtonMessage_Click" Visible="false" />
</div>
</div>
</div>
</div>
</asp:Content>
Content Page:
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="interface" >
<table>
<tr>
<td align="center">
<div class="goog">
<asp:LinkButton ID="LinkFind" runat="server" CssClass="linkgoog">Find</asp:LinkButton>
</div>
</td></tr>
<tr><td align="left">
<div>
<asp:TextBox ID="TextBoxSearch" runat="server" Width="600" Height="40"></asp:TextBox>
<asp:Button ID="ButtonSearch" runat="server" Text="SEARCH" CssClass="loginbt"
onclick="ButtonSearch_Click1" /><br />
</div>
</td></tr>
</table>
</div>
<br />
<div class="interface">
<asp:UpdatePanel ID="updpanel" runat="server">
<ContentTemplate>
<asp:GridView ID="GridAll" runat="server"
onitemcommand="GridAll_ItemCommand" AutoGenerateColumns="false" CellPadding="10" AllowPaging="true" PageSize="3" OnPageIndexChanging="GridAll_PageIndexChanging" >
<Columns>
<asp:TemplateField HeaderText="Name" HeaderStyle-BackColor="#670a0a" HeaderStyle-ForeColor="White" HeaderStyle-Font-Size="20">
<ItemTemplate>
<asp:LinkButton ID="lnkname" runat="server"
Text='<%#Eval("Name") %>'
PostBackUrl='<%#"~/Profile/Profile.aspx?Name="+Eval("UserName") %>' CssClass="welcomeMore"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Department" HeaderStyle-BackColor="#670a0a" HeaderStyle-ForeColor="White" HeaderStyle-Font-Size="20" >
<ItemTemplate>
<span class="googtext"><%#Eval("Department") %></span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Year" HeaderStyle-BackColor="#670a0a" HeaderStyle-ForeColor="White" HeaderStyle-Font-Size="20">
<ItemTemplate>
<span class="googtext"><%#Eval("Year") %></span>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Photo" HeaderStyle-BackColor="#670a0a" HeaderStyle-ForeColor="White" HeaderStyle-Font-Size="20">
<ItemTemplate>
<asp:Image ID="ImageProfile" runat="server" ImageUrl = '<%# "~/ShowImage.ashx?Name=" + Server.UrlEncode(Eval("UserName").ToString()) %>' Width="150" Height="150" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<div class="emptytext">No Match Found</div>
</EmptyDataTemplate>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>
Your help will be appreciated. . . Thank you
You should have only one script manager in master page above update panel.
In any of the content page you can use update panel as there is already script manager in master page. Also you should provide some code for your problem.
I have one master page and Below is one content page's code..I am not able to find dropdownlist dpbatchname 's value inside javascript..i am new to javascript plz,help i want to validate textbox value based on that dropdownlist value..
<asp:Content ID="Content1" ContentPlaceHolderID="Contentplaceholder2" Runat="Server">
<script type="text/javascript" language="javascript">
function ClientValidate(source, arguments) {
var ddl = document.getElementById("dpbatchname");
if (ddl.value.length == 2) {
arguments.IsValid = true;
}
else {
arguments.IsValid = false;
}
}
</script>
<div>
<table style="width: 100%; background-color:Silver" border="1">
<td align="right" width="50%" valign="top">
<asp:Label ID="Label3" runat="server" Text="Select Batch:"
Font-Underline="False" ForeColor="#FF3300" Font-Bold="True" Font-Size="Larger"></asp:Label>
</td>
<td width="50%" valign="top">
<asp:DropDownList ID="dpbatchname" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource5" DataTextField="batch_name"
DataValueField="batch_name" Width="119px" Height="33px">
</asp:DropDownList>
<asp:TextBox ID="tbnooflecture" runat="server" Width="113px" Height="33px"></asp:TextBox>
<asp:CustomValidator id="CustomValidator1" ControlToValidate="tbnooflecture" ClientValidationFunction="ClientValidate"
ValidationGroup="upper" Display="Static" ErrorMessage="Not an even number!" ForeColor="green" Font-Name="verdana" Font-Size="10pt"
runat="server"/>
</td>
</tr>
</div>
Use
<%=dpbatchname.ClientID %>
to get the rendered ID:
document.getElementById("<%=dpbatchname.ClientID %>");