Ajax Autocomplete Not Pulling Data - c#

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";
}

Related

Postback is not working in JQuery dialog

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>

Display:block doesn't work [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I'm so tired because this problem for a long day.
The code below seems to be so long, but it's not hard to understand what I did in that code. Hope you can give me a solution.
I have a panel ID="ASPxPanel2" with stype set to display:none.
After I click on button New --> the panel will be displayed.
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<table>
<tr>
<td>
<dx:ASPxPanel ID="ASPxPanel2" runat="server" Width="700px" Height="150px" RenderMode="Table" CssClass="display_none">//set to display:none here
<PanelCollection>
<dx:PanelContent ID="PanelContent1" runat="server" SupportsDisabledAttribute="True">
<table>
<tr>
<td colspan=4>
<asp:Label ID="LabelError" runat="server" ForeColor="red" Text="">
</asp:Label>
</td
</tr>
<tr>
<td>Đối tượng</td>
<td>
<dx:ASPxComboBox ID="MA_DOI_TUONG" runat="server" ClientIDMode="AutoID"
ValueType="System.String">
</dx:ASPxComboBox>
</td>
<td>Loại</td>
<td >
<dx:ASPxComboBox ID="MA_LOAI" runat="server" ClientIDMode="AutoID"
ValueType="System.String">
</dx:ASPxComboBox>
</td>
<td class="style6">
</td>
<td rowspan=5>
MoreFileUpload
<div style="display: "";" id="div0">
<dx:ASPxTextBox ID="TFileUpload0" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload0" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div1">
<dx:ASPxTextBox ID="TFileUpload1" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload1" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div2">
<dx:ASPxTextBox ID="TFileUpload2" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload2" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div3">
<dx:ASPxTextBox ID="TFileUpload3" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload3" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div4">
<dx:ASPxTextBox ID="TFileUpload4" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload4" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div5">
<dx:ASPxTextBox ID="TFileUpload5" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload5" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div6">
<dx:ASPxTextBox ID="TFileUpload6" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload6" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div7">
<dx:ASPxTextBox ID="TFileUpload7" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload7" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div8">
<dx:ASPxTextBox ID="TFileUpload8" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload8" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div9">
<dx:ASPxTextBox ID="TFileUpload9" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload9" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div10">
<dx:ASPxTextBox ID="TFileUpload10" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload10" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div11">
<dx:ASPxTextBox ID="TFileUpload11" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload11" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div12">
<dx:ASPxTextBox ID="TFileUpload12" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload12" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div13">
<dx:ASPxTextBox ID="TFileUpload13" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload13" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div14">
<dx:ASPxTextBox ID="TFileUpload14" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload14" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div15">
<dx:ASPxTextBox ID="TFileUpload15" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload15" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div16">
<dx:ASPxTextBox ID="TFileUpload16" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload16" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div17">
<dx:ASPxTextBox ID="TFileUpload17" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload17" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div18">
<dx:ASPxTextBox ID="TFileUpload18" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload18" runat="server" accept="png|jpg" Width="180px" size=32 />
</div>
<div style="display: none;" id="div19">
<dx:ASPxTextBox ID="TFileUpload19" runat="server" ClientIDMode="AutoID"
Width="180px" Height="16px">
</dx:ASPxTextBox>
<asp:FileUpload ID="FileUpload19" runat="server" accept="png|jpg" Width="180px" size=27 />
</div>
<div style="text-align: left; width: 263px;" id="divShow">
<a id="linkMore" href="javascript:void(0)" onclick="javascript:ShowHideFileUpload(this.id)">
+ Add More ...</a></div>
<br /><br />
</td>
</tr>
<tr>
<td>Title</td>
<td class="style5" colspan=3>
<dx:ASPxTextBox ID="TITLE" runat="server" ClientIDMode="AutoID"
Width="300px" Height="16px" >
</dx:ASPxTextBox>
</td>
</tr>
<tr><td>Content</td>
<td class="style2" colspan=3>
<FTB:FreeTextBox id="ftCONTENT" runat="server"
ToolbarLayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu,FontForeColorPicker,FontBackColorsMenu,FontBackColorPicker|Bold,Italic,Underline,JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,
Cut,Copy,Paste,Delete;Undo,Redo,InsertTable,EditTable;InsertTableRowAfter,InsertTableRowBefore,DeleteTableRow;InsertTableColumnAfter,InsertTableColumnBefore,DeleteTableColumn"
EditorBorderColorDark="DarkGray" EditorBorderColorLight="DarkGray"
Width="100%" GutterBorderColorDark="Gray" GutterBorderColorLight="White"
ToolbarStyleConfiguration="Office2000" AutoGenerateToolbarsFromString="True" JavaScriptLocation="InternalResource" />
</td>
</tr>
<tr>
<td>FileAttach</td>
<td colspan=3>
<asp:FileUpload ID="PATH" runat="server"
size=40 Width="300px"/></td></tr>
<tr align=center>
<td colspan=5 align=center>
<dx:ASPxButton ID="ASPxButton1" runat="server" ClientIDMode="AutoID"
style="text-align: center" Text="Thêm" HorizontalAlign="Center"
OnClick="btnInsert_Click">
</dx:ASPxButton>
</td>
</tr>
</table>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxPanel>
</td></tr>
</dx:ASPxPanel>
</td>
</tr>
</table>
</asp:Panel> //end ASPXPanel2
<table>
<tr>
td><dx:ASPxPanel ID="ASPxPanel1" runat="server" Width="200px" RenderMode="Table">
</dx:ASPxPanel>
</td>
<td>
<asp:Button ID="btnNew" runat="server" Text="NEW" OnClick="btnNew_Click" />
</td>
</tr>
</table>
In the code behind:
protected void btnNew_Click(object sender, EventArgs e)
{
ASPxPanel2.Attributes.Add("Sytle", "display:block");
//do something more
}
I've added ASPxPanel2.Attributes.Add("Sytle", "display:block"); when btnNew_Click fired, but the ASPxPanel2 isn't displayed.
Does the display:block not work?? Help!!!
UPDATE:
I've found my mistake, typo: "Style" not "Sytle"
But it has a new problem.
There still have a ASPxPanel1 in my webpage. When I set the ASPxPanel2 display:block as default, the Panel1 will be displays below the Panel2. But when I set Panel2 display:none and then set it display:block again in code behind---> the Panel2 display cover Panel1.
Help!!!
I've updated my code above. Please take a look!
Typo
ASPxPanel2.Attributes.Add("Sytle", "display:block");
Should read
ASPxPanel2.Attributes.Add("Style", "display:block");

Button click reloads the page

I have strange problem.
I am implementing zero clipboard in asp.net.
First I created a page without site master and implemented the zero clipboard and it worked perfectly.
Here is the code.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="Locker.test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
<script type="text/javascript" src="Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript" src="Scripts/jquery.zclip.js"></script>
<script type="text/javascript" src="Scripts/jquery.zclip.min.js"></script>
<script>
$(document).ready(function () {
$('#<%=Button1.ClientID%>').zclip({
path: 'ZeroClipboard.swf',
copy: function () { return $('#<%=TextBox1.ClientID%>').val(); }
});
});
</script>
</body>
</html>
Now when I implement this same code on the page that use Master page, it doesn't work. It trigger I reckon post back so that javascript doesn't get executed.
I checked if autopost back it true but it is set to false.
I am not sure what causing this.
Any help will be appreciated.
Here is the code of the page which use Master page.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="searchResult.aspx.cs" Inherits="Locker.searchResult" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
.auto-style1 {
color: #FFFFFF;
font-size: large;
}
.auto-style2 {
color: #000000;
}
.auto-style3 {
color: #000000;
font-size: large;
}
</style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
<p>
<p>
<strong> <span class="auto-style3">Information</span><span class="auto-style1"> </span></strong>
<div style="width:70%; margin: auto auto; text-align:left;">
<asp:Panel ID="Panel1" runat="server">
<br />
<asp:Label ID="Label4" runat="server" style="font-weight: 700; font-size: large" Text="Details for :" CssClass="auto-style2"></asp:Label>
<asp:Label ID="Label5" runat="server" style="font-weight: 700; font-size: large; color: #0000FF"></asp:Label>
<br />
<br />
<asp:Label ID="Label1" runat="server" Font-Bold="False" style="font-weight: 700; font-size: large" Text="Password :" CssClass="auto-style2"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" BorderStyle="Solid" Enabled="False" Font-Size="Medium" ForeColor="Black" Width="213px"></asp:TextBox>
<asp:Button ID="Button3" runat="server" Text="Button" />
<input type="text" id="test_description" value="hi" />
<script type="text/javascript" src="Scripts/jquery-1.9.1.js"></script>
<script type="text/javascript" src="Scripts/jquery.zclip.js"></script>
<script type="text/javascript" src="Scripts/jquery.zclip.min.js"></script>
<script>
$(document).ready(function () {
$('#<%=Button3.ClientID%>').zclip({
path: 'ZeroClipboard.swf',
copy: function () { return $('#<%=TextBox2.ClientID%>').val(); }
});
});
</script>
<br />
<br />
<asp:Label ID="Label6" runat="server" style="font-weight: 700; font-size: large" Text="Description :" CssClass="auto-style2"></asp:Label>
<asp:TextBox ID="TextBox5" runat="server" BorderStyle="Solid" Enabled="False" Font-Size="Medium" Height="48px" TextMode="MultiLine" Width="213px"></asp:TextBox>
<br />
<br />
<asp:Label ID="Label7" runat="server" style="font-weight: 700; font-size: small" Text="Last Editor was " CssClass="auto-style2"></asp:Label>
<asp:Label ID="Label8" runat="server" style="font-weight: 700; font-size: small" CssClass="auto-style2"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Edit" Width="97px" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Update" Visible="False" Width="97px" />
<br />
<br />
<asp:Label ID="Label12" runat="server" style="font-weight: 700; font-size: large; color: #0000FF" Visible="False"></asp:Label>
<br />
<br />
<br />
<br />
</asp:Panel>
</div>
</asp:Content>
If you want to prevent postback, you may set UseSubmitBehavior to false on your Button
<asp:Button ID="Button3" runat="server" Text="Button" UseSubmitBehavior="False"/>
See UseSubmitBehavior description

Script manager won't work

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.

ASP.NET Masterpage Implementation Error

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

Categories

Resources