Cassie Mod

Cassie Mod

  • NA
  • 488
  • 65.4k

textboxvalue in postback is gone

Jul 19 2017 10:11 AM
HI ive got the following error. ive got a aspx page. with some controls. wich can be filled in. However on my postback the value of a forwardToNewPhoneNumberTextBox is gone. so nog it crashes on the regularExpressionValidator.
 
How can i fix this ??
  1. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CallForwardingNotAvailableControl.ascx.cs" Inherits="OneXS.Orion.FrontOffice.Compleet.Portal.Controls.CallForwardingNotAvailableControl" %>  
  2. <asp:UpdatePanel ID="CallForwardingNotAvailableUpdatePanel" runat="server" UpdateMode="Conditional">  
  3.     <ContentTemplate>  
  4.         <%--eror row--%>  
  5.         <div class="row error">  
  6.             <asp:Panel runat="server" ID="FailureTextPanel" Visible="False" class="submit-summary error-summary">  
  7.                 <asp:Literal ID="FailureTextLiteral" runat="server" />  
  8.             </asp:Panel>  
  9.         </div>  
  10.         <%--tekst--%>  
  11.         <div class="row">  
  12.             <div class="part fourth">  
  13.                 <asp:Label ID="isActivatedLabel" runat="server" AssociatedControlID="CallForwardingNotAvailableOption"  
  14.                     CssClass="label-xl">Doorschakelen niet bereikbaar</asp:Label>  
  15.             </div>  
  16.             <%--switch om "Doorschakelen" waarde weer te geven--%>  
  17.             <div class="part sixth switch last">  
  18.                 <asp:RadioButtonList ID="CallForwardingNotAvailableOption" runat="server" CssClass="optionOnOff" RepeatLayout="Flow"  
  19.                     RepeatColumns="3">  
  20.                     <asp:ListItem Value="Off" class="switch-off" Text=" "> </asp:ListItem>  
  21.                     <asp:ListItem Value="On" class="switch-on" Text=" "> </asp:ListItem>  
  22.                 </asp:RadioButtonList>  
  23.             </div>  
  24.             <div class="part third last">  
  25.                 <asp:Panel ID="ForwardToPanel" runat="server" Visible="false" DefaultButton="forwardToPhoneNumberEditLinkButton">  
  26.                     <asp:Label ID="forwardToPhoneNumberLabel" Width="50px" runat="server" AssociatedControlID="forwardToPhoneNumberTextBox"  
  27.                         CssClass="label-xs">Naar :</asp:Label>  
  28.                     <asp:TextBox ID="forwardToPhoneNumberTextBox" runat="server" ReadOnly="true"></asp:TextBox>  
  29.                     <asp:Button ID="forwardToPhoneNumberEditLinkButton" runat="server" CausesValidation="false"  
  30.                         OnClick="CallForwardingNotAvailablePhoneNumberEdit_Click" CssClass="button-s" Text="wijzig" />  
  31.                     <asp:Button ID="forwardToPhoneNumberSaveLinkButton" runat="server" OnClick="CallForwardingNotAvailableSave_Click"  
  32.                         Visible="false" CssClass="button-s" Text="opslaan" />  
  33.                 </asp:Panel>  
  34.             </div>  
  35.         </div>  
  36.         <div class="row">  
  37.             <div id="CallForwardingNotAvailableDialog" title="Waar wilt u naar doorschakelen bij niet bereikbaar?">  
  38.                 <asp:Panel ID="CallForwardingNotAvailableDialogPanel" runat="server">  
  39.                     <asp:Panel runat="server" ID="dialogFailureTextPanel" Visible="False" class="submit-summary error-summary">  
  40.                         <asp:Literal ID="dialogFailureTextLiteral" runat="server" />  
  41.                     </asp:Panel>  
  42.                     <asp:Label ID="forwardToNewPhoneNumberLabel" runat="server" CssClass="label-s" AssociatedControlID="forwardToNewPhoneNumberTextBox">Naar:</asp:Label>  
  43.                     <asp:TextBox ID="forwardToNewPhoneNumberTextBox" runat="server" CssClass="input-xxl"></asp:TextBox>  
  44.                     <asp:RequiredFieldValidator ID="forwardToNewPhoneNumberTextBoxRequiredFieldValidator"  
  45.                         runat="server" ControlToValidate="forwardToNewPhoneNumberTextBox" ErrorMessage="*"  
  46.                         ForeColor="Red" BorderColor="Red" SetFocusOnError="true" CssClass="error-span"  
  47.                         ValidationGroup="ForwardingNotReachableValidationGroup" />  
  48.                     <asp:RegularExpressionValidator ID="forwardToNewPhoneNumberRegularExpressionValidator"  
  49.                         ErrorMessage="*" runat="server" ControlToValidate="forwardToNewPhoneNumberTextBox"  
  50.                         ValidationGroup="ForwardingNotReachableValidationGroup"></asp:RegularExpressionValidator>  
  51.                 </asp:Panel>  
  52.             </div>  
  53.             <asp:Button ID="CallForwardingNotAvailableButton" runat="server" UseSubmitBehavior="false"  
  54.                 ValidationGroup="callForwardingAlwaysValidationGroup" OnClick="CallForwardingNotAvailableSave_Click"  
  55.                 Style="display: none;" />  
  56.         </div>  
  57.     </ContentTemplate>  
  58.     <Triggers>  
  59.         <asp:AsyncPostBackTrigger ControlID="CallForwardingNotAvailableButton" EventName="Click" />  
  60.         <asp:AsyncPostBackTrigger ControlID="forwardToPhoneNumberEditLinkButton" EventName="Click" />  
  61.         <asp:AsyncPostBackTrigger ControlID="forwardToPhoneNumberSaveLinkButton" EventName="Click" />  
  62.     </Triggers>  
  63. </asp:UpdatePanel>  
  64.   
  65. <script type="text/javascript">  
  66.     $(document).ready(function () {  
  67.           
  68.         ApplyJQueryUIInControl();  
  69.         Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);  
  70.   
  71.         function EndRequestHandler(sender, args) {  
  72.             //ApplyJQueryUIInControl();  
  73.         }  
  74.   
  75.         function ApplyJQueryUIInControl() {  
  76.   
  77.             $("#<%= CallForwardingNotAvailableOption.ClientID %>").buttonset();  
  78.   
  79.             $("#CallForwardingNotAvailableDialog").dialog({  
  80.                 resizable: false,  
  81.                 modal: true,  
  82.                 autoOpen: false,  
  83.                 show: "fade",  
  84.                 closeOnEscape: false,  
  85.                 hide: "fade",  
  86.                 buttons: {  
  87.                     "> Ok": function () {  
  88.                         $("#<%= CallForwardingNotAvailableButton.ClientID %>").click();  
  89.                     },  
  90.                     "> Annuleren": function () {  
  91.                         $("#<%= CallForwardingNotAvailableOption.ClientID %>_0").attr("checked""checked");  
  92.                         $("#<%= CallForwardingNotAvailableOption.ClientID %>").buttonset("refresh");  
  93.                         $(this).dialog("close");  
  94.                     }  
  95.                 }  
  96.             });  
  97.   
  98.         }  
  99.             <% if (string.IsNullOrEmpty(forwardToPhoneNumberTextBox.Text))  
  100.     {%>  
  101.   
  102. <%--        $('#CallForwardingNotAvailableDialog').keypress(function (e) {  
  103.                 if (e.keyCode === $.ui.keyCode.ENTER) {  
  104.                     $("#<%= CallForwardingNotAvailableButton.ClientID %>").click();  
  105.                     }  
  106.             });--%>  
  107.   
  108.         //$("#CallForwardingNotAvailableDialog").parent().appendTo($("#<%= CallForwardingNotAvailableUpdatePanel.ClientID %>:first"));  
  109.   
  110.         $("#<%= CallForwardingNotAvailableOption.ClientID %>").on("click", function (e) {  
  111.   
  112.             e.preventDefault();  // this needed to be done otherwise the event is fired twice
  113.   
  114.             // check if option is 'Off'  
  115.             var list = document.getElementById("<%= CallForwardingNotAvailableOption.ClientID %>"); //Client ID of the radiolist  
  116.             var inputs = list.getElementsByTagName("input");  
  117.             var selected;  
  118.             for (var i = 0; i < inputs.length; i++) {  
  119.                 if (inputs[i].checked) {  
  120.                     selected = inputs[i];  
  121.                     break;  
  122.                 }  
  123.             }  
  124.   
  125.             // radio option is selected  
  126.             if (selected) {  
  127.                 // remove later  
  128.                 var selectedValue = selected.value;  
  129.                 if (selectedValue === "Off") {  
  130.                     // show dialog   
  131.                     $("#CallForwardingNotAvailableDialog").dialog("open");  
  132.                     $("#<%= forwardToNewPhoneNumberTextBox.ClientID %>").focus();  
  133.                 } else {  
  134.                     // trigger click event  
  135.                     $("#<%= CallForwardingNotAvailableButton.ClientID %>").click();  
  136.                 }  
  137.             }  
  138.               
  139.             });  
  140.         <% } %>  
  141.     });  
  142. </script> 
 code behind:
 
  1. using System;  
  2. using System.Web;  
  3. using OneXS.Orion.BackOffice.Technic.ServiceAgent.Model;  
  4. using OneXS.Orion.Framework;  
  5. using OneXS.Orion.FrontOffice.Compleet.BusinessLogic;  
  6. using OneXS.Orion.FrontOffice.Compleet.Service;  
  7.   
  8. namespace OneXS.Orion.FrontOffice.Compleet.Portal.Controls  
  9. {  
  10.     public partial class CallForwardingNotAvailableControl : CompleetControl  
  11.     {  
  12.         private static Guid _requestId;  
  13.         private Guid _sessionId;  
  14.         public string jSessionId;  
  15.         public User currentUser;  
  16.         public Features Features { get; set; }  
  17.   
  18.         protected void Page_Load(object sender, EventArgs e)  
  19.         {  
  20.             _sessionId = Guid.Parse(HttpContext.Current.Session["BWSESSION"].ToString());  
  21.             _requestId = Guid.NewGuid();  
  22.             jSessionId = PortalApplication.User.jSessionId;  
  23.   
  24.             try  
  25.             {  
  26.                 //TODO: ik moet nog kijken hoe ik mezelf een een feature kan geven.   
  27.                 if (PortalApplication == null || currentUser == null || Features.CallForwardingNotAvailable)  
  28.                     return;  
  29.   
  30.                 // if it is no postback set the radiobutton  
  31.                 if (!IsPostBack)  
  32.                 {  
  33.                     SetNumberNotAvalaibleSwitch();  
  34.                 }  
  35.   
  36.                 forwardToNewPhoneNumberTextBoxRequiredFieldValidator.Enabled = true;  
  37.                 forwardToNewPhoneNumberRegularExpressionValidator.ValidationExpression = ValidatorConstants.INTEGER_REGEX;  
  38.                 forwardToNewPhoneNumberRegularExpressionValidator.ErrorMessage = ValidatorConstants.INTEGER_MESSAGE;  
  39.                 forwardToNewPhoneNumberRegularExpressionValidator.Text = ValidatorConstants.INTEGER_MESSAGE;  
  40.             }  
  41.             catch (Exception ex)  
  42.             {  
  43.                 PortalApplication.HandleException(ex);  
  44.                 showFailureText();  
  45.             }  
  46.         }  
  47.   
  48.         protected void CallForwardingNotAvailablePhoneNumberEdit_Click(object sender, EventArgs e)  
  49.         {  
  50.             CallForwardingNotAvailableDialogPanel.Visible = true;  
  51.             ForwardToPanel.Visible = false;  
  52.         }  
  53.   
  54.         protected void CallForwardingNotAvailableSave_Click(object sender, EventArgs e)  
  55.         {  
  56.             try  
  57.             {  
  58.                 // get the selected value   
  59.                 var optionIsTurnedOff = CallForwardingNotAvailableOption.SelectedIndex == 0;  
  60.   
  61.                 if (optionIsTurnedOff)  
  62.                 {  
  63.                     var test = forwardToNewPhoneNumberTextBox.Text;// empty somehow  
  64.   
  65.                     // value is set to 'Off'...turn on   
  66.                     // validate everything  
  67.                     var submitError = CompleetApplication.Validate(Page, "ForwardingNotReachableValidationGroup");  // here it keeps crashing because the value of the postback is null  
  68.                     if (!string.IsNullOrEmpty(submitError))  
  69.                         return;  
  70.   
  71.                     // check if textbox isn't empty  
  72.                     if (forwardToNewPhoneNumberTextBox.Visible && string.IsNullOrEmpty(forwardToNewPhoneNumberTextBox.Text))  
  73.                     {  
  74.                         showFailureText("Telefoonnummer is verplicht");  
  75.                         return;  
  76.                     }  
  77.   
  78.                     //Get the trimmed phonenumber  
  79.                     var phonenumber = forwardToNewPhoneNumberTextBox.Text;  
  80.                     char[] charsToTrim = { ' ''\t' };  
  81.                     phonenumber = phonenumber.Trim(charsToTrim);  
  82.   
  83.                     //Get userId  
  84.                     var userId = Request.QueryString["userId"];  
  85.                     var isActive = CallForwardingNotAvailableOption.SelectedIndex == 1;  
  86.   
  87.                     var callForwardingNotReachableMessage = CallForwardingNotAvailableOption.SelectedIndex == 1  
  88.                         ? NumberLogic.UserCallForwardingNotReachableModify(_requestId, _sessionId, jSessionId, userId,  
  89.                             phonenumber, isActive)  
  90.                         : NumberLogic.UserCallForwardingNotReachableModify(_requestId, _sessionId, jSessionId, userId,  
  91.                             null, false);  
  92.   
  93.                     if (callForwardingNotReachableMessage.errorCode != 0 ||  
  94.                         !string.IsNullOrEmpty(callForwardingNotReachableMessage.errorMessage))  
  95.                     {  
  96.                         showFailureText();  
  97.                     }  
  98.                     else  
  99.                     {  
  100.                         //set visiblilty dialogpanel to false and set the ForwardToPanel visibility on true  
  101.                         CallForwardingNotAvailableDialogPanel.Visible = false;  
  102.                         ForwardToPanel.Visible = true;  
  103.   
  104.                         // set values to textbox etc  
  105.                         forwardToPhoneNumberTextBox.Text = phonenumber;  
  106.                     }  
  107.                 }  
  108.                 else  
  109.                 {  
  110.                     // value is set to 'On'...turn off   
  111.                     var userId = Request.QueryString["userId"];  
  112.                     NumberLogic.UserCallForwardingNotReachableModify(_requestId, _sessionId, jSessionId, userId, string.Empty, false);  
  113.                 }  
  114.             }  
  115.             catch (Exception ex)  
  116.             {  
  117.                 PortalApplication.HandleException(ex);  
  118.                 showFailureText();  
  119.             }  
  120.         }  
  121.   
  122.         private void showFailureText(string failureText = "Er is iets fout gegaan tijdens het uitvoeren van uw opdracht.")  
  123.         {  
  124.             FailureTextLiteral.Text = failureText;  
  125.             FailureTextPanel.Visible = true;  
  126.             PortalApplication.EndRequest();  
  127.         }  
  128.   
  129.         protected void CallForwardingNotAvailableOption_SelectedIndexChanged(object sender, EventArgs e)  
  130.         {  
  131.             //Set visisbility based on coditions  
  132.             var isActivated = CallForwardingNotAvailableOption.SelectedIndex == 1;  
  133.             CallForwardingNotAvailableDialogPanel.Visible = isActivated;  
  134.   
  135.             // check if it is active or not, if so.. deactivate  
  136.             if (isActivated) return;  
  137.   
  138.             var userId = Request.QueryString["userId"];  
  139.             NumberLogic.UserCallForwardingNotReachableModify(_requestId, _sessionId, jSessionId, userId, string.Empty, false);  
  140.         }  
  141.   
  142.         private void SetNumberNotAvalaibleSwitch()  
  143.         {  
  144.             // Create the request to get the value of the radiobuttonlist from technic service  
  145.             var userId = Request.QueryString["userId"];  
  146.             var callForwardingNotReachableMessage = NumberLogic.GetUserCallForwardingNotReachable(_requestId, _sessionId, jSessionId, userId);  
  147.             var errorCode = callForwardingNotReachableMessage.errorCode;  
  148.             var errorMessage = callForwardingNotReachableMessage.errorMessage;  
  149.             if (errorCode != 0 || !string.IsNullOrEmpty(errorMessage))  
  150.             {  
  151.                 showFailureText();  
  152.             }  
  153.   
  154.             // Set the response to the radioButton  
  155.             CallForwardingNotAvailableOption.SelectedIndex = Convert.ToInt32(callForwardingNotReachableMessage.callForwardingNotReachable.isActive);  
  156.         }  
  157.     }  

 
 

Answers (1)