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
Related
I have a repeater. i want to get empid when i click on its any row.? how can i ?
My code is:-
<table id="table1" class="yui" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>
Emp name #
</th>
<th>
emp sal
</th>
<th>
emp address
</th>
</tr>
</thead>
<tbody>
<asp:Repeater ID="Repaddressorbbl" runat="server" OnItemCommand="Repaddressorbbl_ItemCommand">
<ItemTemplate>
<tr id="gh" style="cursor: pointer" onclick="Select(this);">
<td style="text-align: center;">
<%#Eval("empname")%>
</td>
<td style="text-align: center;">
<%# Eval("empsal")%>
</td>
<td style="text-align: center;">
<%# Eval("empadd")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
<tfoot>
<tr id="pagerOne1">
<td colspan="4">
<img src="_assets/img/first.png" class="first" />
<img src="_assets/img/prev.png" class="prev" />
<input type="text" class="pagedisplay" />
<img src="_assets/img/next.png" class="next" />
<img src="_assets/img/last.png" class="last" />
<select class="pagesize">
<option selected="selected" value="100">100</option>
<option value="200">200</option>
<option value="400">400</option>
</select>
</td>
</tr>
</tfoot>
</table>
YOu have to create manual postback. But for this to work always, your repeater should bind always, i.e. during each postback.
The following code snippets may guide you.
using System;
namespace PostbackRef.Web
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string arg = Request["__EVENTARGUMENT"];
if (string.IsNullOrEmpty(arg) == false)
{
if (arg.StartsWith("row"))
{
string v = arg.Substring(arg.IndexOf("#") + 1);
txtSelected.Text = v;
}
}
}
//Have to bind repeater always
Repeater1.DataBind();
}
protected string getPostbackReference(string Name)
{
return ClientScript.GetPostBackEventReference(this, "rowEvent#" + Name);
}
}
}
The aspx markup looks like this:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PostbackRef.Web._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
p
{
font-size: 12pt;
}
p:hover
{
background-color: Gray;
font-weight: bold;
color: White;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate>
<p onclick="<%# getPostbackReference((string)Container.DataItem) %>">
<%# Container.DataItem %></p>
</ItemTemplate>
</asp:Repeater>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetNames"
TypeName="PostbackRef.Web.MyDs"></asp:ObjectDataSource>
<asp:HiddenField ID="hfValue" runat="server" />
</div>
<div>
Clicked :
<asp:TextBox ID="txtSelected" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
I've used an ObjectDataSource which returns a string array of names, but the choice of datasource is entirely yours. Here I've used just for e.g. sake.
Note that I am calling Repeater1.Databind() on Page_Load irrespective of postback or not. There are probably better ways to do this. But most of the code came exactly here
Here the sample with checkbox control. Same way you gonna use with button or any click events. Make it one hidden for empid.
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox box = sender as CheckBox;
RepeaterItem item = box.NamingContainer as RepeaterItem;
HiddenField hf = item.FindControl("HiddenField1") as HiddenField;string id = hf.Value;
}
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged" />
<asp:HiddenField ID="HiddenField1" Value='<%# Eval("id") %>' runat="server" />
</ItemTemplate>
a quick write -up
<asp:Repeater ID="Repaddressorbbl" runat="server" OnItemCommand="Repaddressorbbl_ItemCommand">
<ItemTemplate>
<tr id="gh" style="cursor: pointer" onclick="Select('<%# Eval("EmployeeID")%>');">
<td style="text-align: center;">
<%#Eval("empname")%>
</td>
<td style="text-align: center;">
<%# Eval("empsal")%>
</td>
<td style="text-align: center;">
<%# Eval("empadd")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
try this one
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.
Here is my effort for using JQuery mobile with asp.net webform. Below is the code I have used in the Default.aspx page. It's a very simple code
Below is the complete code of the aspx page.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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> Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0b1/jquery.mobile-1.0b1.min.js">
</script>
</head>
<body>
<form id="form1" runat="server">
<!-- Start of first page -->
<div data-role="page" id="foo">
<div data-role="header">
<h1>Mobile Login</h1>
</div><!-- /header -->
<div data-role="content">
<table width="100%">
<tr width="100%">
<td width="30%" align="right" valign="middle">
<asp:Literal ID="lblUserName" runat="server" Text="User Name"></asp:Literal>
</td>
<td width="50%">
<input type="text" maxlength="20" id="UserName" style="width:50%;" runat="server" />
</td>
</tr>
<tr width="100%">
<td width="50%" align="right">
<asp:Literal ID="Literal1" runat="server" Text="Password"></asp:Literal>
</td>
<td width="50%">
<input type="text" maxlength="20" id="Password" style="width:50%;" runat="server" />
</td>
</tr>
<tr width="100%">
<td width="50%" align="right">
</td>
<td width="50%">
<table width="100%">
<tr>
<td width="30%">
<asp:Button ID="btnLogin" runat="server" Text="Login"
OnClick="btnLogin_Click" />
</td>
<td width="30%">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="ui-btn-active"
OnClick="btnCancel_Click" />
</td>
<td width="40%">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div><!-- /content -->
<div data-role="footer">
<h4>
# All right reserved.
</h4>
</div><!-- /footer -->
</div><!-- /page -->
</form>
</body>
</html>
Now on the server side
protected void btnLogin_Click(object sender, EventArgs e)
{
Response.Redirect("Home.aspx",true);
}
protected void btnCancel_Click(object sender, EventArgs e)
{
UserName.Value = "";
Password.Value = "";
}
but when I am clicking the login/cancel button nothing happen other than the Url is changed from
http://localhost:2278/Mobile/Default.aspx
to
http://localhost:2278/Mobile/Default.aspx#/Mobile/Default.aspx
What is wrong in my code? Can't I access Server side functions from ASP.NET server controls in JQuery Mobile? I am aware that it can be done better in MVC but that's not a option for me in this case.
Please help
This is because .net adds type="submit" to Button control by default. You need to set that to false and I would also set CausesValidation to false too, like this:
<asp:Button ID="btnLogin" runat="server" Text="Login"
OnClick="btnLogin_Click" CausesValidation="False" UseSubmitBehavior="False" />
in all fairness however, I wouldn't have used a server-side event just to navigate away on button click. You can achieve that with much easier way:
Login
..that's, of course, assuming you don't have to do any other server-side operations before navigating away.
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.
I would like to trigger a PostBack when the asp:LinkButton "addToCartButton" is clicked (see code below).
I have declared a PostBack Trigger with the asp:UpdatePanel "updPnlProductsList" (see code below).
<asp:Panel ID="pnlProductsList" runat="server" Visible="false">
<asp:UpdatePanel ID="updPnlProductsList" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div class="featured">
<h3>Product listing</h3>
<div class="product clearfix">
<asp:DataList ID="productsList" runat="server" DataKeyField="prodid" OnItemCommand="productsList_ItemCommand"
OnItemDataBound="productsList_ItemDataBound">
<HeaderTemplate>
<table>
<col width="85" />
<col width="315" />
<col width="85" />
<col width="315" />
<col width="85" />
<tr>
<th align="left">
</th>
<th align="left">
Product Description
</th>
<th align="center">
In Stock
</th>
<th align="center">
Price
</th>
<th align="left">
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td height="85" valign="top">
<asp:HyperLink ID="standardImage" Style="float: left; margin-right: 5px; border: 2px;
vertical-align: top;" Width="75" Height="75" runat="server"></asp:HyperLink>
</td>
<td height="85" valign="top">
<asp:LinkButton ID="lbProductDescription" CommandName="show_product" runat="server" />
<p>
<asp:Label ID="MfPartNo" runat="server" /></p>
</td>
<td height="85" align="center" valign="top">
<p>
<asp:Label ID="inventoryTextLabel" runat="server" /></p>
</td>
<td style="padding-bottom: 10px;" height="85" align="center" valign="top">
<div class="product-actions clearfix">
<p class="price">
<strong>
<asp:Label ID="sellPriceLabel" runat="server" Style="font-size: 0.9em;" /></strong>
</p>
</div>
</td>
<td style="padding-bottom: 10px;" height="85" valign="top">
<div class="product-actions clearfix">
<p class="view">
<asp:LinkButton ID="addToCartButton" runat="server" Text="<span><strong>Buy</strong></span>"
CommandName="add_to_cart" class="newactionbutton" />
</p>
</div>
</td>
</tr>
</div>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan="5" style="border-bottom: dotted 1px gray; line-height: 0.1em;">
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:DataList>
</div>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="addToCartButton" />
</Triggers>
</asp:UpdatePanel>
</asp:Panel>
<!-- /The all new Products List. -->
Unfortunately, when I run this code I get the error:
InvalidOperationException: A control with ID 'addToCartButton' could not be found for the trigger in UpdatePanel 'updPnlProductsList'.
Would someone please help me reference the 'addToCartButton' within the ItemTemplate of the DataList.
Or maybe I can cause a PostBack in the asp:LinkButton code behind? I'm coding in C#.
Kind Regards
Walter
Edit2: First solution suggested cannot work. Try this (derived from what you already tried) as suggested here:
productsList_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(e.Item.FindControl("addToCartButton"));
// Add this update call.
updPnlProductsList.Update();
}
}
Add your control on the server side event OnRowDataBound(). At this point you will be adding the right id to the Triggers list.
Edit1: This is what I had in mind. I did not test it...
protected void gv_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType = DataControlRowType.DataRow)
{
// TODO: Find control within the row.
Control control = null;
var trigger = new AsyncPostBackTrigger();
trigger.ControlID = control.ID;
updPnlProductsList.Triggers.Add(trigger);
}
}