|
Rank: Advanced Member Groups: Member
Joined: 6/9/2007 Posts: 98
|
Hi, How i can register a hidden field to update when i use a callback panel. I have create an example page to show you the problem
Code: HTML/ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="eoTest.aspx.cs" Inherits="eoTest" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<%@ Register src="modules/modPageGallery.ascx" tagname="modPageGallery" tagprefix="uc1" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<eo:CallbackPanel ID="CallbackPanel1" runat="server" Height="150px"
Triggers="{ControlID:Button1;Parameter:}" Width="200px">
<asp:Button ID="Button1" runat="server" Text="Works not"
onclick="Button1_Click" />
<br />
<asp:Label ID="Label1" runat="server" Text="0"></asp:Label>
</eo:CallbackPanel>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Works" />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
Code: C#
public partial class eoTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.Request.Form["myField"] == null) { Label1.Text = "0"; }
else { Label1.Text = this.Request.Form["myField"]; }
if (this.Request.Form["myField2"] == null) { Label2.Text = "0"; }
else { Label2.Text = this.Request.Form["myField2"]; }
}
protected void Button1_Click(object sender, EventArgs e)
{
int value = Convert.ToInt32(Label1.Text) + 1;
Page.ClientScript.RegisterHiddenField("myField", value.ToString());
}
protected void Button2_Click(object sender, EventArgs e)
{
int value = Convert.ToInt32(Label2.Text) + 1;
Page.ClientScript.RegisterHiddenField("myField2", value.ToString());
}
}
Button2 works correct and add the button when you click. Button1 never adds 1 to the value Thanks for a solution Philipp
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
You will not be able to do that. HiddenFields are rendered outside of the CallbackPanel thus not updated. You can explicitly place a HiddenField inside the CallbackPanel, or place a parent control (such as a Panel) inside the CallbackPanel and the dynamically create the HiddenField as child controls of that parent control, but RegisterHiddenField itself will not work.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 6/9/2007 Posts: 98
|
My main problem is, that i use a registered hidden field to save the viewstate of the page in a compressed form.
|
|
Rank: Advanced Member Groups: Member
Joined: 6/9/2007 Posts: 98
|
I have found the solution. I must save the viewstate in the hidden field "__VIEWSTATE" and than it works fine.
|
|
Rank: Advanced Member Groups: Member
Joined: 6/9/2007 Posts: 98
|
Can you add a method like
Code: C#
System.Web.UI.ScriptManager.RegisterHiddenField(this, "__VSTATECOMPRESSED", Convert.ToBase64String(bytes))
to register hidden field to your scriptmanager that locatet outside the updatepanel?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
No. We have no plan to do so. It will over complicate the controls and only benefit very few users. Sorry about it!
|
|