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.
Related
I have a button which has probably been implemented wrong, since it causes an error 500. The page works fine without the button and I'm not sure where the problem lies.
The .aspx:
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<div id="notify_form">
<p>Please enter a new email:</p>
<table class="ms-formtable" width="100%">
<tr>
<td><input type="text" runat="server" id="txtEmail"/></td>
</tr>
<tr>
<td class="ms-formlabel"></td>
<td>
<asp:Button runat="server" ID="btnSubmit" OnClick='SaveEmail' />
<asp:Button runat="server" ID="btnCancel" OnClientClick="window.frameElement.cancelPopUp(); return false;"/>
</td>
</tr>
</table>
</div>
</asp:Content>
The SaveEmail method does nothing at the moment.
I have the below markup in a master page, and when I access a page using that master, I get the error:
An extender can't be in a different UpdatePanel than the control it
extends.
<asp:UpdatePanel ID="UpdatePanel99" runat="server">
<ContentTemplate>
<script type="text/javascript">
function OnAutoCompleteSelected(source, eventArgs) {
$("#autoCompleteHidden").val(eventArgs._text);
__doPostBack("autoCompleteHidden", "");
}
</script>
<table>
<tr>
<td style="height: 25px">Search By
</td>
<td>
<asp:DropDownList ID="ddlSearchBy" runat="server" OnSelectedIndexChanged="ddlSearchBy_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem>Emp No</asp:ListItem>
<asp:ListItem>ID No</asp:ListItem>
<asp:ListItem>Surname</asp:ListItem>
</asp:DropDownList>
</td>
<td>
<asp:ImageButton ID="imgBtnSearch" runat="server" Height="20px" ImageUrl="~/Images/Apps/mySearch2.png"
Width="20px" OnClick="imgBtnSearch_Click" />
</td>
</tr>
<tr>
<td colspan="3" style="height: 25px; margin-left: 80px;">
<div>
<asp:HiddenField runat="server" ID="autoCompleteHidden" OnValueChanged="autoCompleteHidden_ValueChanged" />
<asp:TextBox ID="txtSearchField" runat="server" Width="200px"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" TargetControlID="txtSearchField"
ServicePath="~/AutoComplete.asmx" ServiceMethod="GetEmployees" Enabled="False" CompletionInterval="100"
MinimumPrefixLength="1" CompletionSetCount="10000" OnClientItemSelected="OnAutoCompleteSelected"
CompletionListCssClass="CompletionList" CompletionListItemCssClass="CompletionListItem" CompletionListHighlightedItemCssClass="CompletionListHighlightedItem">
</ajaxToolkit:AutoCompleteExtender>
</div>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
There is only one UpdatePanel on the master page, and the extended control, txtSearchField is contained well within it only. What am I doing wrong?
I found another AutoCompleteExtender for the same textbox outside of the UpdatePanel.
I have follow two listboxes and and a left and right button.. which are contained in a updatepanel. The only problem is when clicking on the left or right button the page refreshes which is not desired.
<asp:UpdatePanel runat="server" ID="ExportUpdatePanel">
<ContentTemplate>
<div class="exportWrapper">
<table class="exportFilter">
<tr>
<td>
<h2>
<%= ExportSelectDateLabel %></h2>
</td>
</tr>
<tr>
<td>
<label>
<%= ExportFromDateLabel %></label>
<asp:TextBox runat="server" ID="exportFilterFromDate" CssClass="exportDates"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<label>
<%= ExportToDateLabel %></label>
<asp:TextBox runat="server" ID="exportFilterToDate" CssClass="exportDates"></asp:TextBox>
</td>
</tr>
</table>
<table class="exportFilter">
<tr>
<td colspan="3">
<h2>
<%= ExportSelectColumnsLabel %></h2>
</td>
</tr>
<tr>
<td>
<label>
<%= ExportAvailableColumnLabel %></label>
</td>
<td>
</td>
<td>
<label>
<%= ExportSelectedColumnLabel %></label>
</td>
</tr>
<tr>
<td>
<asp:ListBox runat="server" ID="exportFilterAvailableColumns" SelectionMode="Multiple" CssClass="exportListBox">
</asp:ListBox>
</td>
<td class="exportButtonsTd">
<div>
<asp:LinkButton runat="server" OnClick="MoveSelectedClick"><span><img src="/images/source/arrow-right.png" alt="Move Right"/></span></asp:LinkButton>
</div>
<div class="mt_10">
<asp:LinkButton runat="server" OnClick="RemoveSelectedClick"><span><img src="/images/source/arrow-left.png" alt="Move Left"/></span></asp:LinkButton>
</div>
</td>
<td id="exportedSelectedColumn">
<asp:ListBox runat="server" ID="exportFilterSelectedColumns" SelectionMode="Multiple" CssClass="exportListBox">
</asp:ListBox>
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Any ideas ?
As per your code ExportUpdatePanel section will refresh when you click on link button inside UpdatePanel. it is not full page refresh. default update mode of update panel is always. that means:
the UpdatePanel control's content is updated on every postback that originates from anywhere on the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls and postbacks from controls that are not inside UpdatePanel controls.
here is sample test:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
On click event both Label1 and Label2 will update.
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToLongTimeString();
Label2.Text = DateTime.Now.ToLongTimeString();
}
but only Label2 will change because it will refresh by the update panel.
Before using update panels, please read some article on how update panels work. For example, this one: http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers
Add UpdateMode="Conditional" and ChildrenAsTriggers="true" attributes to your update panel, and it should work as you want.
<asp:UpdatePanel runat="server"
ID="ExportUpdatePanel"
UpdateMode="Conditional"
ChildrenAsTriggers="true">
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.
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