From: Rick on 24 Mar 2010 16:17 Can someone help me? I have a HTMLSelect control that is populated on the Page_Load event. I want to basically when the user makes a selection to populate session variables upon an Item change in the HTMLSelect. I have tried just about everything I've read and can think of, but have not been able to get this to work. Currently I get a script error that Hidden1 field is undefined after the post back. My code: ASPX: <script language="javascript" type="text/javascript"> function dothepostback() { //ddCustList gets renamed var selval = document.getElementById("_ctl2_ddCustList").value; Hidden1.value = selval; //Post back the page document.forms[0].submit(); } </script> <table cellpadding="0" cellspacing="0" width="100%" class="TopNavMenu"> <tr> <td> <CYBERAKT:ASPNETMENU id="ASPNetMenu" clientscriptlocation="/aspnetmenu_client/" menustyle="ClassicHorizontal" runat="server"></CYBERAKT:ASPNETMENU> </td> <td align="right"> <input type="text" id="Hidden1" name="Hidden1" value="" runat="server" enableviewstate="true" /> Choose Customer:<select id="ddCustList" runat="server" onchange="dothepostback()" enableviewstate="true"><option></option></select> </td> </tr> </table> Code Behind to get Hidden Field Value: Dim hdnSearch As New HtmlInputText Dim x As String hdnSearch = FindControl("Hidden1") x = hdnSearch.Value Session("HIDVal") = x I cannot use an asp DropDownList control because it requires a Form tag with runat="server", which you cannot have multples in a web page Tthe web site I'm working with was initially built to Inherit different parts of a page and then put it all together at the end (Not well planned out and to change it would be a massive undertaking). So other parts of the page may already have the Form tag with runat="server" Thanks in Advance!
From: Alexey Smirnov on 25 Mar 2010 03:04 On Mar 24, 9:17 pm, "Rick" <rfem...(a)newsgroups.nospam> wrote: > Can someone help me? I have a HTMLSelect control that is populated on the > Page_Load event. I want to basically when the user makes a selection to > populate session variables upon an Item change in the HTMLSelect. I have > tried just about everything I've read and can think of, but have not been > able to get this to work. > Currently I get a script error that Hidden1 field is undefined after the > post back. > Well, you need to find Hidden1 field exactly as you do it for selval instead of var selval = document.getElementById("_ctl2_ddCustList").value; Hidden1.value = selval; do var selval = document.getElementById("_ctl2_ddCustList").value; var h = document.getElementById("<%=Hidden1.getClientID()%>"); You can't use Hidden1 by referring to its ASP.NET's id from js because it has another id on the client. Just open your result page in source view in the browser and you will what I mean. To fix it I used getClientID() which should return it. Hope this helps
From: Rick on 25 Mar 2010 12:40 Thanks! That solved the issue with the HiddenField Error, but when I get to the code behind, the hidden field value is gone. Viewstate does not appear to be working. Any suggestions? function dothepostback() { //Get Drop down list var seldd = document.getElementById("<%=ddCustList.UniqueID()%>"); //Get Hidden Field var hidctl = document.getElementById("<%=Hidden1.UniqueID()%>"); //Set Hidden field to selected item hidctl.value = seldd.value; //post back the page document.forms[0].submit(); } <table cellpadding="0" cellspacing="0" width="100%" class="TopNavMenu"> <tr> <td> <CYBERAKT:ASPNETMENU id="ASPNetMenu" clientscriptlocation="/aspnetmenu_client/" menustyle="ClassicHorizontal" runat="server"></CYBERAKT:ASPNETMENU> </td> <td align="right"> <input type="hidden" id="Hidden1" name="Hidden1" runat="server" enableviewstate="true" /> Choose Customer:<select id="ddCustList" onchange="dothepostback()" runat="server" enableviewstate="true"><option></option></select> </td> </tr> </table> Code behind: Dim hdnSearch As New HtmlInputHidden Dim x As String hdnSearch = FindControl("Hidden1") x = hdnSearch.Value "Alexey Smirnov" <alexey.smirnov(a)gmail.com> wrote in message news:d010f415-4cdf-469d-9c5c-c547663aff3d(a)t23g2000yqt.googlegroups.com... On Mar 24, 9:17 pm, "Rick" <rfem...(a)newsgroups.nospam> wrote: > Can someone help me? I have a HTMLSelect control that is populated on the > Page_Load event. I want to basically when the user makes a selection to > populate session variables upon an Item change in the HTMLSelect. I have > tried just about everything I've read and can think of, but have not been > able to get this to work. > Currently I get a script error that Hidden1 field is undefined after the > post back. > Well, you need to find Hidden1 field exactly as you do it for selval instead of var selval = document.getElementById("_ctl2_ddCustList").value; Hidden1.value = selval; do var selval = document.getElementById("_ctl2_ddCustList").value; var h = document.getElementById("<%=Hidden1.getClientID()%>"); You can't use Hidden1 by referring to its ASP.NET's id from js because it has another id on the client. Just open your result page in source view in the browser and you will what I mean. To fix it I used getClientID() which should return it. Hope this helps
From: Alexey Smirnov on 13 Apr 2010 13:38 On Mar 25, 6:40 pm, "Rick" <rfem...(a)newsgroups.nospam> wrote: > Thanks! That solved the issue with the HiddenField Error, but when I get to > the code behind, the hidden field value is gone. Viewstate does not appear > to be working. Any suggestions? > > function dothepostback() { > //Get Drop down list > > var seldd = document.getElementById("<%=ddCustList.UniqueID()%>"); > > //Get Hidden Field > > var hidctl = document.getElementById("<%=Hidden1.UniqueID()%>"); > > //Set Hidden field to selected item > > hidctl.value = seldd.value; > > //post back the page > > document.forms[0].submit(); > > } > > <table cellpadding="0" cellspacing="0" width="100%" class="TopNavMenu"> > > <tr> > > <td> > > <CYBERAKT:ASPNETMENU id="ASPNetMenu" > clientscriptlocation="/aspnetmenu_client/" menustyle="ClassicHorizontal" > runat="server"></CYBERAKT:ASPNETMENU> > > </td> > > <td align="right"> > > <input type="hidden" id="Hidden1" name="Hidden1" runat="server" > enableviewstate="true" /> > > Choose Customer:<select id="ddCustList" onchange="dothepostback()" > runat="server" enableviewstate="true"><option></option></select> > > </td> > > </tr> > > </table> > > Code behind: > > Dim hdnSearch As New HtmlInputHidden > > Dim x As String > > hdnSearch = FindControl("Hidden1") > > x = hdnSearch.Value > > "Alexey Smirnov" <alexey.smir...(a)gmail.com> wrote in message > > news:d010f415-4cdf-469d-9c5c-c547663aff3d(a)t23g2000yqt.googlegroups.com... > On Mar 24, 9:17 pm, "Rick" <rfem...(a)newsgroups.nospam> wrote: > > > Can someone help me? I have a HTMLSelect control that is populated on the > > Page_Load event. I want to basically when the user makes a selection to > > populate session variables upon an Item change in the HTMLSelect. I have > > tried just about everything I've read and can think of, but have not been > > able to get this to work. > > Currently I get a script error that Hidden1 field is undefined after the > > post back. > > Well, you need to find Hidden1 field exactly as you do it for selval > > instead of > > var selval = document.getElementById("_ctl2_ddCustList").value; > Hidden1.value = selval; > > do > > var selval = document.getElementById("_ctl2_ddCustList").value; > var h = document.getElementById("<%=Hidden1.getClientID()%>"); > > You can't use Hidden1 by referring to its ASP.NET's id from js because > it has another id on the client. Just open your result page in source > view in the browser and you will what I mean. To fix it I used > getClientID() which should return it. > > Hope this helps The easiest way to debug js is to put alert(); in the code. Try to get on what step you get wrong value.
|
Pages: 1 Prev: Firefox not performing client-side validation Next: substring |