How to reatin the changes done in the asp.net custom server control by javascript? During the postback / page reloads, changes done by the javascript in custom control is not retained.
Every changes made on the client side needs to be put in input fields for the server to be able to get the updates on a postback. What kind of things are you changing in javascript?
How to reatin the changes done in the asp.net custom server control by javascript? During the postback / page reloads, changes done by the javascript in custom control is not retained.
You can use a hidden field to store the value changed by javascript,and then at the beginning of Page_Load,you can use Request.Form["hiddenfield"] to fetch the value。
You can use a hidden field to store the value changed by javascript,and then at the beginning of Page_Load,you can use Request.Form["hiddenfield"] to fetch the value。
Hi,
I've created hidden field in custom control, the value is changing from client page, when postback occurs it is not retaining the latest value as the control is created once on postback.
I've created hidden field in custom control, the value is changing from client page, when postback occurs it is not retaining the latest value as the control is created once on postback.
How to reatin the changes done in the asp.net custom server control by javascript? During the postback / page reloads, changes done by the javascript in custom control is not retained.
Save all changes in input fied like text box and other text box make sure that all are server side control mean runat ="server" is set. and fill all this field by javascripts so that will be retain there view by viewstate.
My Tech Blogs MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
Used Context.Request.Form[hiddenfield.UniqueUrl] in property to get the changes made by javascript
public string Text
{
get
{
if(this.Page.IsPostBack)
ViewState["Text"] = this.Context.Request.Form["sTextHiddenField"].ToString();
return ViewState["Text"].ToString();
}
set
{
ViewState["Text"] = value;
}
}
anandhan
Member
1 Points
44 Posts
Retain changes made by javascript in custom control
Apr 28, 2012 10:02 PM|LINK
Hi,
How to reatin the changes done in the asp.net custom server control by javascript? During the postback / page reloads, changes done by the javascript in custom control is not retained.
mm10
Contributor
6445 Points
1187 Posts
Re: Retain changes made by javascript in custom control
Apr 29, 2012 11:11 AM|LINK
Every changes made on the client side needs to be put in input fields for the server to be able to get the updates on a postback. What kind of things are you changing in javascript?
anandhan
Member
1 Points
44 Posts
Re: Retain changes made by javascript in custom control
Apr 29, 2012 04:39 PM|LINK
Hi,
Please refer the below link, i've added the complete code of my custom control & test page.
http://stackoverflow.com/questions/10367847/get-selected-text-asp-net-custom-server-control
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Retain changes made by javascript in custom control
Apr 30, 2012 01:22 AM|LINK
You can use a hidden field to store the value changed by javascript,and then at the beginning of Page_Load,you can use Request.Form["hiddenfield"] to fetch the value。
Reguards!
anandhan
Member
1 Points
44 Posts
Re: Retain changes made by javascript in custom control
Apr 30, 2012 09:46 AM|LINK
Hi,
I've created hidden field in custom control, the value is changing from client page, when postback occurs it is not retaining the latest value as the control is created once on postback.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Retain changes made by javascript in custom control
May 01, 2012 05:28 AM|LINK
Where and how did you create it?
amitpatel.it
Star
7976 Points
1865 Posts
Re: Retain changes made by javascript in custom control
May 01, 2012 05:44 AM|LINK
Save all changes in input fied like text box and other text box make sure that all are server side control mean runat ="server" is set. and fill all this field by javascripts so that will be retain there view by viewstate.
MCPD Enterprise and Web Application
MCTS Web, Window and Enterprise Application
anandhan
Member
1 Points
44 Posts
Re: Retain changes made by javascript in custom control
May 01, 2012 05:14 PM|LINK
I've created the hidden field in CreateChildControls();
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Retain changes made by javascript in custom control
May 02, 2012 12:58 AM|LINK
And please make sure that OnInit or OnLoad event,please use something like Context.Request.Form[hiddenfield.UniqueUrl] to accept the value。
anandhan
Member
1 Points
44 Posts
Re: Retain changes made by javascript in custom control
May 02, 2012 11:12 AM|LINK
Registered Hidden Field in OnPreRender()
Page.ClientScript.RegisterHiddenField("sTextHiddenField", (string)ViewState["Text"]);
Selected Text Property
Used Context.Request.Form[hiddenfield.UniqueUrl] in property to get the changes made by javascript
public string Text { get { if(this.Page.IsPostBack) ViewState["Text"] = this.Context.Request.Form["sTextHiddenField"].ToString(); return ViewState["Text"].ToString(); } set { ViewState["Text"] = value; } }