I have a web page that contain login control, I face a problem :
The code behind not matched to the design.For example , it gives me an error
Login1 cannot be found in the current context
And when I try to add event to the login it is written as the following:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void LoginButton_Click(object sender, EventArgs e)
{
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1
{
height: 28px;
}
</style>
</head>
<body >
<form id="form1" runat="server">
Name retrieved from ViewState: <asp:Label runat="server" id="NameLabel" />
<div>
</div>
<asp:Login ID="Login1" runat="server" onauthenticate="Login1_Authenticate">
<LayoutTemplate>
<table border="0" cellpadding="1" cellspacing="0"
style="border-collapse:collapse;">
<tr>
<td>
<table border="0" cellpadding="0">
<tr>
<td align="center" colspan="2">
Log In</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User
Name:</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">
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
</td>
<td>
<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">
<asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color:Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right" colspan="2" class="style1">
<asp:Button ID="LoginButton" runat="server" CommandName="Login"
Text="Log In" ValidationGroup="Login1" onclick="LoginButton_Click" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
</form>
</body>
</html>
Any idea to solve this problem , the big problem is that the code doesn't see the design and vise verse
Firstly :
Make sure that your name space is :
WebApplication4
and the class name is:
_Default
in your code behind file.like this:
namespace WebApplication4
{
public partial class _Default : System.Web.UI.Page
{
}
}
secondly:
Make sure the consistency of the .aspx.designer.cs file.
I mean make sure that there is a reference of your control in this file .like this:
protected global::System.Web.UI.WebControls.Login Login1;
and tell us which Visual studio version does u use.
It sounds like the designer.cs file is out of sync. If you go into the designer.cs file, you can declare the control, like this:
/// <summary>
/// Login1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Login Login1;
You might also try cutting and pasting the markup, so the designer registers all of the controls.
Related
I'm new to ASP.NET and seems I screwed up my Web Form page that is based off of a Master.
It seems I mixed some invalid html codes but can't figure out why.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Clips.aspx.cs" Inherits="Clip.Clips" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:EntityDataSource ID="entityDataSource" runat="server" ConnectionString="name=ClipEnt" DefaultContainerName="ClipEnt" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Clips" EntityTypeFilter="Clip" OnSelecting="EntityDataSource_Selecting">
</asp:EntityDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="entityDataSource">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
</Columns>
</asp:GridView>
<div>
<h1>Sending Email</h1>
<table>
<tr>
<td>From:</td>
<td>
<asp:TextBox ID="txtFrom" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>From EMail:</td>
<td>
<asp:TextBox ID="txtFromEmail" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>To:</td>
<td>
<asp:TextBox ID="txtTo" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>To Email:</td>
<td>
<asp:TextBox ID="txtToEmail" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>Subject:</td>
<td>
<asp:TextBox ID="txtSubject" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>Message:</td>
<td>
<asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Height="138px"
Width="467px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<asp:Button ID="btnSend" runat="server" Text="Send Email"
onclick="btnSend_Click" />
</td>
</tr>
</table>
<asp:Label ID="Label1" runat="server" ForeColor="Blue" />
</div>
</form>
</body>
</html>
</asp:Content>
In the masterpage you have something like this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
You only need to have this stripped markup in the content page. Notice that I have removed DOCTYPE, <html>, <head>, <body> and <form> tags from content page - they will be rendered from Site.Master master page.
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Clips.aspx.cs" Inherits="Clip.Clips" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:EntityDataSource ID="entityDataSource" runat="server" ConnectionString="name=ClipEnt" DefaultContainerName="ClipEnt" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="Clips" EntityTypeFilter="Clip" OnSelecting="EntityDataSource_Selecting">
</asp:EntityDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="entityDataSource">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
</Columns>
</asp:GridView>
<div>
<h1>Sending Email</h1>
<table>
<tr>
<td>From:</td>
<td>
<asp:TextBox ID="txtFrom" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>From EMail:</td>
<td>
<asp:TextBox ID="txtFromEmail" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>To:</td>
<td>
<asp:TextBox ID="txtTo" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>To Email:</td>
<td>
<asp:TextBox ID="txtToEmail" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>Subject:</td>
<td>
<asp:TextBox ID="txtSubject" runat="server" Width="250px"></asp:TextBox>
</td>
</tr>
<tr>
<td>Message:</td>
<td>
<asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine" Height="138px"
Width="467px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<asp:Button ID="btnSend" runat="server" Text="Send Email"
OnClick="btnSend_Click" />
</td>
</tr>
</table>
<asp:Label ID="Label1" runat="server" ForeColor="Blue" />
</div>
</asp:Content>
Some points to remember when developing an asp.net web site -
asp.net web forms can contain only one form tag with the attribute runat='server'. So, when a web form inherits from a masterpage, it inherits the form tag from the master page. therefore, no need to add a form tag separately to the web form.
Common parts of the page should be placed in the master page, where as changing parts should be placed in the web forms that inherit the master page. Site headers and footers are static to every page. so they should be placed on the master page. contents of the web site changes from page to page. so they should be placed on the web forms that inherit the master page.
Links to common resources, i.e. site style sheets and javascript files should also be placed once in the masterpage. web forms that inherit the masterpage will automatically inherit them.
these are some of the things by following which you can easily develop web forms with master pages.
I have created a user control which has 2 date controls(start date and end date). Now in my aspx page I am using the same user control twice with id as parent and child. Now i want that the dates in the child user control should be within the dates provided in the parent user control.
Please refer to the below code snippet, i want the dates selected to be within the range of the dates.
ASCX Page:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="EffectiveDate.ascx.cs"
Inherits="UserControlDemo.EffectiveDate" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %>
<asp:ScriptManager runat="server" ID="scriptmanger1" EnablePageMethods="true">
</asp:ScriptManager>
<table id="Table5" width="99%" cellspacing="5">
<tr>
<td valign="middle" width="20%">
<asp:Label ID="Label4" runat="server" Style="white-space: nowrap;" Text="Effective Start Date"></asp:Label>
</td>
<td valign="middle">
<asp:TextBox ID="attPrdStartdate" runat="server"></asp:TextBox>
<asp:Label ID="Label8" runat="server" ForeColor="Red" Text="*"></asp:Label>
<asp:ImageButton ID="Image3" runat="server" ImageUrl="/Images/CalendarImage.png"
Style="margin-bottom: -5px" />
<ajaxtoolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender5" runat="server"
TargetControlID="attPrdStartdate" ValidChars="1234567890/" />
<ajaxtoolkit:CalendarExtender ID="CalendarExtender3" runat="server" TargetControlID="attPrdStartdate"
PopupButtonID="Image3" Format="MM/dd/yyyy">
</ajaxtoolkit:CalendarExtender>
<asp:CompareValidator ID="CompareValidator5" runat="server" ControlToValidate="attPrdStartdate"
Display="Dynamic" ErrorMessage="Invalid Date" ForeColor="Red" Operator="DataTypeCheck"
Type="Date" Style="font-size: smaller">
</asp:CompareValidator>
<asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="attPrdStartdate" Type="Date"
Display="Dynamic" ErrorMessage="Dates out of range" ForeColor="Red" EnableClientScript="False"></asp:RangeValidator>
</td>
</tr>
<tr>
<td valign="middle">
<asp:Label ID="Label5" runat="server" Style="white-space: nowrap;" Text="Effective End Date"></asp:Label>
</td>
<td valign="middle">
<asp:TextBox ID="attPrdEnddate" runat="server"></asp:TextBox>
<asp:Label ID="Label9" runat="server" ForeColor="Red" Text="*"></asp:Label>
<ajaxtoolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender6" runat="server"
TargetControlID="attPrdEnddate" ValidChars="1234567890/" />
<ajaxtoolkit:CalendarExtender ID="CalendarExtender4" runat="server" TargetControlID="attPrdEnddate"
PopupButtonID="Image4" Format="MM/dd/yyyy">
</ajaxtoolkit:CalendarExtender>
<asp:ImageButton ID="Image4" runat="server" ImageUrl="/Images/CalendarImage.png"
Style="margin-bottom: -5px" />
<asp:CompareValidator ID="CompareValidator6" runat="server" ControlToValidate="attPrdEnddate"
Display="Dynamic" ErrorMessage="Invalid Date" ForeColor="Red" ControlToCompare="attPrdStartdate"
Operator="GreaterThan" Type="Date" Style="font-size: smaller">
</asp:CompareValidator>
<asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="attPrdEnddate" Type="Date"
Display="Dynamic" ErrorMessage="Dates out of range" ForeColor="Red" EnableClientScript="False"></asp:RangeValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label runat="server" ID="errlblBaseln" Text="" ForeColor="Red" Font-Size="smaller"></asp:Label>
</td>
</tr>
</table>
ASCX Code Behind:
namespace UserControlDemo
{
public partial class EffectiveDate : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
RangeValidator1.MaximumValue = endDate.ToShortDateString();
RangeValidator1.MinimumValue = startDate.ToShortDateString();
RangeValidator2.MaximumValue = endDate.ToShortDateString();
RangeValidator2.MinimumValue = startDate.ToShortDateString();
}
private DateTime startDate;
private DateTime endDate;
public DateTime StartDate
{
get { return startDate; }
set { startDate = value; }
}
public DateTime EndDate
{
get { return endDate; }
set { endDate = value; }
}
}
}
my aspx page:
<uc:EfectiveDate ID="MyDates" runat="server" StartDate="01/01/2013" EndDate="12/12/2013" />
I think you are trying to do something like this.
Parent
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Parent.ascx.cs" Inherits="StackOverFlow.Parent" %>
<table>
<tr>
<td>Parent Start Date </td>
<td>
<asp:TextBox runat="server" ID="txtStartDate" />
</td>
</tr>
<tr>
<td>Parent End Date </td>
<td>
<asp:TextBox runat="server" ID="txtEndDate" />
</td>
</tr>
</table>
Child
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Child.ascx.cs" Inherits="StackOverFlow.Child" %>
<table>
<tr>
<td>Child Start Date </td>
<td>
<asp:TextBox runat="server" ID="txtStartDate" />
</td>
</tr>
<tr>
<td>Child End Date </td>
<td>
<asp:TextBox runat="server" ID="txtEndDate" />
</td>
</tr>
</table>
Your Page
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="StackOverFlow.WebForm1" %>
<%# Register TagPrefix="p" Src="~/Parent.ascx" TagName="Parent" %>
<%# Register TagPrefix="c" Src="~/Child.ascx" TagName="Child" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<p:Parent ID="parent" runat="server"></p:Parent>
</td>
</tr>
<tr>
<td>
<c:Child ID="child" runat="server"></c:Child>
</td>
</tr>
<tr><td>
<asp:Button Text="Compare" ID="btnCompare" runat="server" OnClick="btnCompare_Click" /></td></tr>
</table>
</div>
</form>
</body>
</html>
Code behind
protected void btnCompare_Click(object sender, EventArgs e)
{
TextBox txtParentStartDate = (TextBox)parent.FindControl("txtStartDate");
if (txtParentStartDate!=null)
{
DateTime dtParentStartDate = Convert.ToDateTime(txtParentStartDate.Text.Trim());
}
//likewise get other dates and compare
}
Hope this will help you.
i am trying to do a program to upload a document in one page and want to navigate to another page with that document name. i wrote code like this
<%# Page Title="Home Page" Language="VB" %>
<html>
<head>
<style type="text/css">
.style1
{
width: 100%;
}
.style3
{
width: 185px;
}
.style4
{
width: 129px;
}
</style>
<script language="javascript">
function doc_save() {
document.forms[0].submit;
action = "mynew_page.aspx";
}
doc_save();
</script>
<script language ="vbscript " runat ="server" >
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call save_click()
End Sub
Public Sub save_click()
Response.Write("Saving...")
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td class="style4">
<asp:Button ID="back" runat="server" Text="Back" />
</td>
<td class="style3">
<asp:Button ID="save" runat="server" Text="Save" onClick="doc_save()" />
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label1" runat="server" Text="File Name"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label2" runat="server" Text="Description"></asp:Label>
</td>
<td class="style3">
<textarea id="txtarea" name="txtarea" runat ="server" ></textarea></td>
</tr>
<tr>
<td class="style4">
<asp:Label ID="Label3" runat="server" Text="File Upload"></asp:Label>
</td>
<td class="style3">
<asp:FileUpload ID="FileUpload1" runat="server" Width="330px" />
</td>
</tr>
</table>
</form>
</body>
</html>
when i run the program it is showing error like below.
of course this code is not yet complete, can u please help to finish this one.
The reason for the error is that you are putting an "onclick" attribute on a server side element (the asp:button). In this context onclick refers to the server side action to be taken when the button is clicked. but because the function you have named doesn't exist in the server code it fails.
Given you have a javascript function I assume this is what you want to call. In this case you should use the onClientClick attribute. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx has information on this and reading around that should give you a better understanding of the subject.
Should the Button call the javascript function? if so, you need to set onClientClick
The error message says you do not have "doc_save()" defined in your aspx code page. you have to convert **<asp:button>** to html **<input>** control and then remove the tag "runat=server" or use OnClientClick on current control as given in other answer.
When the form is displayed, I'd like to set focus to the CurrentPassword textbox. What is the easiest way to do this? Is there a way to access it directly using its ID? Apparently, because it is nested, referencing the control by its ID results in an unrecognized variable. Alternatively, I could write an ugly FindControl statement (some like) like this:
ChangePassword1.Controls(1).Controls(0).Controls(0).Controls(0).Controls...etc...FindControl("CurrentPassword")
but, besides being ugly, this seems brittle to GUI changes.
I could also write a recursive FindControl statement, but while it is convenient, it is less efficient than a more direct reference.
Suggestions, Ol' Wise Community?
<%# Page Title="" Language="VB" MasterPageFile="~/Master Pages/MasterPage.master" AutoEventWireup="false" CodeFile="ChangePassword.aspx.vb" Inherits="ChangePassword" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="phPageContent">
<h1 style="text-align: left;">
Change Password
</h1>
<hr />
<asp:ChangePassword ID="ChangePassword1" runat="server">
<ChangePasswordTemplate>
<table cellpadding="1" cellspacing="0" style="border-collapse: collapse;">
<tr>
<td>
<table cellpadding="2">
<tr>
<td align="right">
<asp:Label ID="CurrentPasswordLabel" runat="server" AssociatedControlID="CurrentPassword" CssClass="CaptionLabel">Current Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="CurrentPassword" runat="server" CssClass="DefaultTextBox" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="CurrentPasswordRequired" runat="server" ControlToValidate="CurrentPassword" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="NewPasswordLabel" runat="server" AssociatedControlID="NewPassword" CssClass="CaptionLabel">New Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="NewPassword" runat="server" CssClass="DefaultTextBox" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" ControlToValidate="NewPassword" ErrorMessage="New Password is required." ToolTip="New Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="ConfirmNewPasswordLabel" runat="server" AssociatedControlID="ConfirmNewPassword" CssClass="CaptionLabel">Confirm New Password:</asp:Label>
</td>
<td>
<asp:TextBox ID="ConfirmNewPassword" runat="server" CssClass="DefaultTextBox" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="ConfirmNewPasswordRequired" runat="server" ControlToValidate="ConfirmNewPassword" ErrorMessage="Confirm New Password is required." ToolTip="Confirm New Password is required." ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:CompareValidator ID="NewPasswordCompare" runat="server" ControlToCompare="NewPassword" ControlToValidate="ConfirmNewPassword" Display="Dynamic" ErrorMessage="The Confirm New Password must match the New Password entry." ValidationGroup="ChangePassword1"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="center" colspan="2" style="color: Red;">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
</td>
</tr>
<tr>
<td align="right">
<asp:Button ID="ChangePasswordPushButton" runat="server" CommandName="ChangePassword" Text="Submit" ValidationGroup="ChangePassword1" />
</td>
<td>
<asp:Button ID="CancelPushButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</ChangePasswordTemplate>
<MailDefinition BodyFileName="~/EmailTemplates/ChangePassword.htm" From="info-noreply#pandavisa.com" IsBodyHtml="True" Subject="Your password has changed">
</MailDefinition>
</asp:ChangePassword>
</asp:Content>
Based on the reply below, I changed the ClientIdMode of the CurrentPassword Textbox to "Static." I then added the following shown after the pre-existing first line:
<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="phPageContent">
<script type="text/javascript">
$().ready(function () {
//$('.DefaultTextBox:eq(0)').focus();
$('#CurrentPassword').focus();
});
</script>
But I got the following error, same error when I uncommented the first suggestion.
Microsoft JScript runtime error: Object expected
You open for some jQuery?
$().ready(function(){
$('.DefaultTextBox:eq(0)').focus();
});
This is an old question, but I'm posting the C# way of referencing the correct textboxes in case anybody looks at this.
TextBox txtCurrentPassword = (TextBox)changepasswordCtl.ChangePasswordTemplateContainer.FindControl("CurrentPassword");
TextBox txtNewPassword = (TextBox)changepasswordCtl.ChangePasswordTemplateContainer.FindControl("NewPassword");
TextBox txtConfirmNewPassword = (TextBox)changepasswordCtl.ChangePasswordTemplateContainer.FindControl("ConfirmNewPassword");
I'm using FCKEditor on my asp.net web page. It appears beautifully, and the editor looks really good on the front end. Only problem is, the .Value property is not being set on the postback. No matter what changes the user makes to the value of the control on the page, when I click "Submit", the .Value property remains blank.
I have Googled for other solutions, and most of them are of the variety where there's some conflict with Ajax, such as this and this. My problem is not solved by these solutions; it's much more fundamental than that. I'm not doing anything to do with Ajax; I'm just a simple asp.net newbie with a simple web form, and the value property is not being set on postback, not in IE and not in FF.
It appears that at least one other person has had this problem, but no solution yet.
Any ideas?
Thanks!
New information:
I tried this out on a "hello world" test web site - and the test web site works 100%. There is obviously a problem on my page, but I have no idea where to begin tracking this down.
Here's the markup of my page, in case anyone can see anything obvious that my newbie eyes can't:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="EmailTemplateEditForm.aspx.vb"
Inherits="EEI_App.EmailTemplateEditForm" %>
<%# Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<!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>EEI - Email Template</title>
<link rel="stylesheet" href="EEI.css">
<script language="javascript" id="jssembleWare" src="sembleWare.js"></script>
<style type="text/css">
.style1
{
height: 251px;
}
.style2
{
width: 2%;
height: 251px;
}
.style3
{
height: 490px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<%# register src="header.ascx" tagname="header" tagprefix="uc1" %>
<%# register src="footer.ascx" tagname="footer" tagprefix="uc1" %>
<uc1:header ID="header1" runat="server" />
<!-- main content area -->
<div class="content">
<!-- title of the page -->
<div class="boxheader">
Email Template
</div>
<div class="standardbox">
<!-- Start Page Main Contents-->
<!-- error messages -->
<div class="errorbox">
<asp:Label ID="lblError" CssClass="ErrorControlStyle" runat="server" EnableViewState="False"
Width="100%"></asp:Label>
</div>
<table class="contenttable">
<tr>
<td align="left" valign="top" class="style3">
<div class="actionbox">
<div class="navheadertitle">
Navigation</div>
<ul>
<li>
<asp:LinkButton ID="btnSubmit" CssClass="LinkButtonStyle" runat="server">Submit</asp:LinkButton>
</li>
<li>
<asp:LinkButton ID="btnCancel" CssClass="LinkButtonStyle" runat="server" CausesValidation="false">Cancel</asp:LinkButton>
</li>
</ul>
</div>
</td>
<td align="left" valign="top" class="style3">
<p>
</p>
<table>
<tr class="MCRSFieldRow">
<td class="MCRSFieldLabelCell">
<asp:Label ID="lblEmailTemplate_TemplateName" CssClass="LabelStyle" runat="server"
Width="175">Template Name</asp:Label>
</td>
<td class="MCRSFieldEditCell">
<asp:TextBox ID="txtEmailTemplate_TemplateName" CssClass="TextBoxStyle" runat="server"
Width="100%"></asp:TextBox>
</td>
<td class="MCRSFieldLabelCell">
<asp:Label ID="lblEmailTemplate_TemplateType" CssClass="LabelStyle" runat="server"
Width="175">Template Type</asp:Label>
</td>
<td class="MCRSFieldEditCell">
<asp:RadioButtonList ID="rblEmailTemplate_TemplateType" CssClass="RadioButtonListStyle"
runat="server" RepeatColumns="1" RepeatDirection="Horizontal" Width="135px">
<asp:ListItem Value="1">Cover Letter</asp:ListItem>
<asp:ListItem Value="2">Email</asp:ListItem>
</asp:RadioButtonList>
</td>
<td class="MCRSRowRightCell">
</td>
</tr>
<tr class="MCRSFieldRow">
<td class="MCRSFieldLabelCell">
Composition Date
</td>
<td class="MCRSFieldEditCell">
<asp:Label ID="lblEmailTemplate_CompositionDate" CssClass="ElementLabelStyle" runat="server"
Width="175"></asp:Label>
</td>
<td class="MCRSFieldLabelCell">
Last Used Date
</td>
<td class="MCRSFieldEditCell">
<asp:Label ID="lblEmailTemplate_LastUsedDate" CssClass="ElementLabelStyle" runat="server"
Width="175"></asp:Label>
</td>
<td class="MCRSRowRightCell">
</td>
</tr>
<tr class="MCRSFieldRow">
<td class="MCRSFieldLabelCell">
Composed By
</td>
<td class="MCRSFieldEditCell" colspan="3">
<asp:Label ID="lblPerson_FirstNames" CssClass="ElementLabelStyle" runat="server"></asp:Label>
<asp:Label ID="lblPerson_LastName" CssClass="ElementLabelStyle" runat="server"></asp:Label>
</td>
<td class="MCRSRowRightCell">
</td>
</tr>
<tr class="MCRSFieldRow">
<td class="MCRSFieldLabelCell">
<asp:Label ID="lblEmailTemplate_Subject" CssClass="LabelStyle" runat="server" Width="175">Subject</asp:Label>
</td>
<td class="MCRSFieldEditCell" colspan="3">
<asp:TextBox ID="txtEmailTemplate_Subject" CssClass="TextBoxStyle" runat="server"
Width="100%"></asp:TextBox>
</td>
<td class="MCRSRowRightCell">
</td>
</tr>
<tr class="MCRSFieldRow">
<td class="style1">
<asp:Label ID="lblEmailTemplate_Body" CssClass="LabelStyle" runat="server" Width="175">Body</asp:Label>
</td>
<td class="style1" colspan="3">
<FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server" Height="500px">
</FCKeditorV2:FCKeditor>
</td>
<td class="style2">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<p>
<a class="InputButtonStyle" href="#_swTopOfPage">Top of Page</a>
</p>
</div>
<uc1:footer ID="footer1" runat="server" />
<p>
<asp:TextBox ID="txtEmailTemplate_Body" CssClass="TextAreaStyle" Rows="4" runat="server"
Width="100%" Height="16px" Visible="False"></asp:TextBox>
</p>
</form>
</body>
</html>
Problem with getting value from FCKeditor (FCKeditor.Value) at ASP.Net
1. If initial value FCKeditor.Value not set, there is no problem, all values, which are placed to FCKeditor can get with FCKeditor.Value.
2. Problem: if initial value FCKeditor.Value is not null, then if I want get value, it gives me only initial value.
I have solved!!!!
I spent the whole day ... Hardly found the answer.
Specially registered to write a reply!
Look! Example:
// Set initial value to FCKeditor
void Page_Init(object sender, EventArgs e)
{
DataTable dT_01 = new DataTable();
dT_01 = DataLayerMainContent.ArticlesSelect(2);
FCKeditor_Edit.Value = dT_01.Rows[0]["ArticleText"].ToString();
}
Attention!!!
You have not to do this here!!
protected void Page_Load(object sender, EventArgs e)
{
// Not here!!!
}
// And get Value from FCKeditor
protected void Btn_ContentEditedSave_Click(object sender, EventArgs e)
{
//FCKeditor_Edit.Value
// And add this value to DataBase
DataLayerAdminPost.ContentMainEdit(1, FCKeditor_Edit.Value);
Response.Redirect(Request.RawUrl);
}
Main Idea!
Set initial value to FCKeditor at Page_Init!
Have you got ViewState enabled? ANS = Yes
EDIT: OK, then inside the Page_Init event try adding the following:
Page.RegisterRequiresPostBack(FCKeditor1);
The solution above didn't work for me, however i found solution here
Here's code what I used
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterOnSubmitStatement(
this,
this.GetType(),
"AjaxHack", "for ( var i = 0; i < parent.frames.length; ++i ) if ( parent.frames[i].FCK ) parent.frames[i].FCK.UpdateLinkedField();");
}
Hope that saves someones day. I was looking for the solution for 2 months.
Cheers