1

TI have defined a hidden filed in aspx:-

<asp:HiddenField runat ="server" ID="hfBrand" value = "False" />

A combo-box control is calling a JavaScript function function:-

<telerik:RadComboBox ID="Brands" runat="server"  
                onclientselectedindexchanged="LoadProperties"
                AutoPostBack="True">
</telerik:RadComboBox>

In that function , I am trying to set that hidden field value to "True":-

function LoadProperties(sender, eventArgs)
{ 
var lblBrand = document.getElementById('<%= hfBrand.ClientID %>').value;
alert(lblBrand);
document.getElementById('<%= hfBrand.ClientID %>').value = "True";
var NewlblBrand = document.getElementById('<%= hfBrand.ClientID %>').value
alert(NewlblBrand)
}

On Server Side (Brands.aspx.cs), I'm trying to fetch the hidden field value:-

if (hfBrand.Value == "True")
        brandIDSelected = "10";
else
        brandIDSelected = "20";

QUESTION:- --> hfbrand.Value is still 'False', even when I had set it to 'True' in javascript. Why it so. Please help.

Thanks

Kings
  • 1,551
  • 12
  • 32
  • 52
  • You set the value to `True` but you're testing for `true`. The equals is case sensitive – themarcuz May 10 '12 at 09:55
  • edited the mistake. hfBrand.Value still shows 'false'. That is the problem. – Kings May 10 '12 at 10:00
  • Does your combo do postback? if so please verify what happens first, posting back or clientSelectedIndexChanging? – Yasser Zamani May 10 '12 at 10:03
  • @YasserZamani - On selecting an item from ComboBox, first 'clientSelectedIndexChanging' occurs, then 'page Load'. – Kings May 10 '12 at 10:08
  • Does http://stackoverflow.com/questions/4993406/asp-net-hidden-field-not-retaining-value-when-updated-from-code-behind solve your issue too? – Yasser Zamani May 10 '12 at 10:14
  • @Kings In one simple step you have ask two questions. I think that you need to try more with debugging and real understand your code. Maybe here is ones again your fault that you can not read. Are this partial post back ? Did you correct the code, did you check what you get in the .Form ? do you check what actually value gets with the hfBradn, when you call call that ? maybe is not have find the time to update his value on code behind if you get it on init(). Give more try because if you have stop on this simple issue you never going to finish the project. – Aristos May 10 '12 at 10:18
  • @Kings and still here you have keep the bug code form question 1. – Aristos May 10 '12 at 10:19
  • @Aristos - Thanks for rectifying my errorneous code. I have corrected that. Ragarding understanding the understanding of the flow of the code, its causing post back. But I am finding it difficult to check whether its partial or not. And really appreciate your suggestion for putting more effort, but I have indeed the entire 5-6 hours on doing the same. And I'm still trying... – Kings May 10 '12 at 10:38
  • i m php developper but i try to help; i think the server code are executed one time and can't detect javascript changes unless by using ajax – khaled_webdev May 10 '12 at 10:45
  • @Kings Get all the post back using Request.Form (make a break, or print the Request.Form, in the page) and check if there is your control and if have the value that you search for (for start). If you see there your value with the correct value then you try to get it before the control set it. (and you can get it using the Request.Form[UniqueNameID] – Aristos May 10 '12 at 11:27

0 Answers0