Textbox does not exist in current Context - c#

I am sure this question comes up a lot, but I didn't find an answer in your archives.
Here is my ASP code:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="RCC_ChangePassword.ascx.cs" Inherits="Regal.Web._Tester.RCC.RCC_ChangePassword" %>
<div id="modal-password-change">
<div class="modal-contents">
<h1>Change Password</h1>
<div class="intro">Use the form below to change the password for your RCC account. Use the new password next time you log in.</div>
<asp:Label ID="CurPass" Text="Current Password" runat="server"></asp:Label>
<asp:Textbox id="CurrentPass" runat="server" CssClass="required"></asp:Textbox>
<asp:Label ID="NwPass" Text="New Password*" runat="server"></asp:Label>
<asp:Textbox id="NewPass" runat="server" CssClass="required"></asp:Textbox>
<asp:Label ID="CnfPass" Text="Confirm Password" runat="server"></asp:Label>
<asp:Textbox id="ConfirmPass" runat="server" CssClass="required"></asp:Textbox>
<h4>Your password must include ALL of the following</h4>
<ul class="notes">
<li>At least 8 characters (not more than 16 characters)</li>
<li>At least one number</li>
</ul>
<asp:Button ID="submit" Cssclass="btn blue wide" runat="server" Text="Save Changes" OnClick="btnSubmit_click"></asp:Button>
</div>
</div><!-- #modal-password-change .modal -->
And here is the line that I am getting the error on:
// Change actual password for the new password
String testPass1 = NewPass.Text;
if (regalMemberRepo.ChangePassword(oUser.Email, oUser.Password, testPass1))
can you see anything odd about my code?
Thank you in advance.

This happens to me often with VS. Take a look in the designer file and see if VS created an entry in there for the text box? Make sure you don't have another file somewhere with a similar declaration.
Many times, best way to fix this is to delete, re-create and re-name the form. We're not supposed to edit the designer file ourselves.

After adding a TextBox programmatically I received this error when trying to access its Text property. Here's a quick function I used to access it:
private string GetTextFromTextBox(string strTextBoxName)
{
Control[] txtBox = Controls.Find(strTextBoxName, true);
if (txtBox != null)
{
return txtBox[0].Text;
}
else
{
return null;
}
}

Related

.net C# post value as a querystring to another page with button

beginner here looking for a good way to post data from a textbox to another page as a query string
<div class="col-md-4">
<h2>Find a Player</h2>
<p>
<img alt="Find a Player" src="images/user.png" style="width: 64px; height: 64px" /><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Submit" />
</p>
<p>
Just trying to get it to post to:
http:\website\depth_chart?recid=griffey
where griffey is the data that was put into the textbox.
You can use the property PostBackUrl:
<asp:Button ID="Button2" runat="server" Text="Submit" PostBackUrl="http:\website\depth_chart?recid=griffey" />
where the value for PostBackUrl should be changed on the client while the users write in the textbox using the onkeyup or onkeydown property:
<asp:TextBox ID="TextBox1" onkeyup="alert('TextBox1 onkeyup fired');"
The issue you could face in mixing the javascript with the back-end asp controls is retrieving the IDs, you could solve by creating the js in the code-behind:
string changeScript = "<script language='javascript'> function SomeValueChanged() {" +
"document.getElementById('" + MyTextBox.ClientID +
"').value = 'Some values may have been changed.'; }</script>";
// Add the JavaScript code to the page.
if (!ClientScript.IsClientScriptBlockRegistered("SomeValueChanged"))
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "SomeValueChanged", changeScript);
}
BUT if you're trying to apply this logic to your app, forcing how an ASP.NET WebForm project should work, I can tell you that you're going in the wrong direction. It feels like there is a design issue.

RadAjaxLoadingPanel does not works with DNN

I have a dnn site, which has a label and an imagebutton, clicking on which replaces the label with textbox and user can enter their text, once submitted the label will be updated with this text. Now clicking on the imagebutton causes the page to postback, i don't want a postback for this, hence i have placed telerik RadAjaxLoadingPanel control, so the cool loading div gets displayed while processing is going on, but for some reason it's not working, It always throws below error:
Please, see whether wrapping the code block, generating the exception, within RadCodeBlock resolves the error.
Below is the markup of my page: (I tried the wrapping the code with RadScriptBlock and RadCodeBlock, in both case it throws same error as above)
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default">
</telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<a class="subscribetoday" href="#">
<strong>Subscribe Today!</strong> <asp:Label ID="lblsubscribemsg" runat="server" Text="12 issues for $14.95"></asp:Label>
<asp:ImageButton ID="imgEditSubscribe" runat="server"
OnClick="imgEditSubscribe_Click" ToolTip='Edit' ImageUrl="~/images/edit.gif" AlternateText='Edit' Visible="false" />
<div id="editsubscribe" runat="server" visible="false">
<asp:TextBox ID="txtSubscribe" runat="server"></asp:TextBox> <asp:ImageButton ID="imgSave" runat="server"
OnClick="imgSave_Click" OnClientClick="return validateSubscribeNote();" ToolTip='Save' ImageUrl="~/images/save.gif" AlternateText='Save' /> <asp:ImageButton ID="imgCancel" runat="server"
OnClick="imgCancel_Click" ToolTip='Cancel' ImageUrl="~/images/cancel.gif" AlternateText='Cancel' />
</div>
<img src="img/prosound-subscribe.png" alt="Subscribe Today!">
</a>
</telerik:RadScriptBlock>
</telerik:RadAjaxPanel>
Can anyone tell me where i am going wrong with this.
The problem is with other server code blocks on the page (<%=%> for example, generally - <% ... %>), not with this concrete piece of code you are trying to AJAX-enable. You can read more here: http://docs.telerik.com/devtools/aspnet-ajax/controls/ajax/radcodeblock-and-radscriptblock
So, you should find the place where those code blocks are used and wrap THEM in a RadCodeBlock controls. It is often scripts that reference controls, e.g.:
<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
<script>
function getReference() {
return $find("<%=someControl.ClientID%>");
}
</script>
</telerik:RadCodeBlock>
With DNN, however, I cannot say where these may originate.
Thus, your other option is to use an <asp:UpdatePanel> control to get AJAX requests instead of full postbacks. The native AJAX toolset also offers the <asp:UpdateProgress> control that you can use instead of RadAjaxPanel.

Validation Group in Asp.Net MultiView

I have multiView and Validation group in my code. According to my code when user press button all the data in views needs to be saved.
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="viewGegevens" runat="server">
<asp:TextBox ID="txtCompanyname" MaxLength="100" runat="server" CssClass=""></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ToolTip="Bedrijfsnaam vereist!"
Display="Dynamic" ErrorMessage="*" ValidationGroup="Save" ControlToValidate="txtCompanyname"
CssClass="required-asterics"></asp:RequiredFieldValidator>
<div>
<asp:LinkButton ID="btnSave1" Text="Opslaan" runat="server" CssClass="btn-ctrl right" OnClick="txtSave1_Click" ValidationGroup="Save">Save
</asp:LinkButton>
<asp:LinkButton ID="btnCancel1" Text="Annuleren" runat="server" CssClass="btn-ctrl right" OnClick="txtCancel1_Click"> Cancel
</asp:LinkButton>
</div>
</asp:View>
<asp:View ID="viewGegevens2" runat="server">
<asp:TextBox ID="txtBillingPostalCode" runat="server" CssClass="" MaxLength="100"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ToolTip="Postcode vereist!"
ErrorMessage="*" ValidationGroup="Save" ControlToValidate="txtBillingPostalCode"
Display="Dynamic" CssClass="required-asterics"></asp:RequiredFieldValidator>
<div>
<asp:LinkButton ID="btnSave2" Text="Opslaan" runat="server" CssClass="btn-ctrl right" OnClick="txtSave2_Click" ValidationGroup="Save">Save
</asp:LinkButton>
<asp:LinkButton ID="txtCancel2" Text="Annuleren" runat="server" CssClass="btn-ctrl right" OnClick="txtCancel2_Click"> Cancel
</asp:LinkButton>
</div>
</asp:View>
</asp:MultiView>
My problem is i need to fire required field validation in both tabs either user press btnSave1 or btnSave2.
But now if i press btnSave1 it only fires validations in 1st tab only. How can i solve this?
Found a workaround for this that works in my case. I made the different views validate when the tabs are clicked in the code behind preventing the user from leaving the view without validating.
protected void Tab3_Click(object sender, EventArgs e)
{
Page.Validate("YourValidationGroup");
if (Page.IsValid)
{
Tab1.CssClass = "Initial";
Tab2.CssClass = "Initial";
Tab3.CssClass = "Clicked";
MainView.ActiveViewIndex = 2;
}
}
I know this in an old thread but figured I'd throw it out there for future people experiencing a similar issue.
The answer is no, you can't do it like this out of the box.
ASP.NET Multiview is designed to display and validate one view at a time. So only the active view's html is delivered to the client's browser.
There is a workaround but may give you problems if you are using MultiView's ActiveViewChanged event.
Another option would be to refactor your page and use two divs, one for each step, making one or the other visible when changing from first to second step, and validate entire page once in the last step. This will require you to do more work with javascript.
Try this:
SelectView(0);
Validate();
if (IsValid)
{
SelectView(1);
Validate();
if (IsValid)
{
SelectView(2);
Validate();
if (IsValid)
{
SelectView(3);
Validate();
if (IsValid)
{
UpdateHeader();
Response.Redirect("FinConfLanding.aspx");
}
}
}
}

Show confirmation textbox after entry with JavaScript

Before we begin, I would like to convey that I have limited to no knowledge on the JavaScript language. The only things I've used is JQueryUI - and even that is copy paste.
Currently, I have a user registration page, with all the standard TextBox inputs. I would like to, however, slide down a secondary 'Confirm email' and 'confirm password' whenever a user enters text into the original text box.
I understand the community likes to help those who can prove they helped themselves, but the only thing I currently have to show is me trying to lookup solutions for this and failing.
Could someone please show me a way to do this?
Edit: Code of the password box
<div class="ctrlHolder">
<asp:Label ID="Label9" runat="server" Font-Bold="True" Text="Password"></asp:Label>
<asp:Label ID="Label11" runat="server" CssClass="styleLabelWatermarkWashout" Text="**********"></asp:Label>
<br />
<%--data-default-value="Placeholder text"--%>
<asp:TextBox ID="txtRegisterPassword" runat="server" CssClass="textInput styleTextBoxCenter required"
TextMode="Password" MaxLength="20"></asp:TextBox>
</div>
So, assuming you can create markup similar to this:
<div class="ctrlHolder">
<asp:Label ID="PasswordLabel" runat="server" Font-Bold="True" Text="Password"></asp:Label>
<asp:Label ID="Label11" runat="server" CssClass="styleLabelWatermarkWashout" Text="**********"></asp:Label>
<br />
<%--data-default-value="Placeholder text"--%>
<asp:TextBox ID="txtRegisterPassword" runat="server" CssClass="textInput styleTextBoxCenter required" TextMode="Password" MaxLength="20"></asp:TextBox>
</div>
<div id="confirm-password-box" class="ctrlHolder">
<asp:Label ID="ConfirmPasswordLabel" runat="server" Font-Bold="True" Text="Confirm Password"></asp:Label>
<asp:Label ID="Label12" runat="server" CssClass="styleLabelWatermarkWashout" Text="**********"></asp:Label>
<br />
<%--data-default-value="Placeholder text"--%>
<asp:TextBox ID="txtConfirmRegisterPassword" runat="server" CssClass="textInput styleTextBoxCenter required" TextMode="Password" MaxLength="20"></asp:TextBox>
</div>
You'd want to add some CSS rules to make #confirm-password-box hidden by default. Then, add this script code somewhere on the page (preferably as close to closing </body> tag as possible):
<script>
$(function(){
$('#<%: txtRegisterPassword.ClientID %>').on('blur', function(event){
$('#confirm-password-box').slideToggle('slow');
});
});
</script>
The blur event occurs when the control loses focus. You don't really want to listen for keyup, since that would require this code being called every time a user entered a character into the password box...
Note that this particular chunk of jQuery code requires jQuery 1.7 or higher, so use NuGet to update your script reference (if you're not using anything else that requires an older version of jQuery).
I would add a reference to jquery to the page you are working on.
Then make a new script (on the page or in a separate .js file) which attaches a new function to the onkeyup event for the textboxes. Something like this.
$(document).ready(function()
{
$('mytextbox').bind('keyup', function() {
$('myCOnfirmationTextbox').slideDown();
};
});
This will attach this function to all elements corresponding to the "mytextbox" class or ID. So if you have an input <input type="text" id="email" class="emailInput"/> then you would use $('#email') to bind the event to this particular element. Or you use $('.Emailinput') to bind to all input elements for emails.
By the way, I haven't tested the code, but this or something very similar should work.
If you use a separate .js file, then don't forget to reference it in your page as well.
You can use innerHTML to have a new textbox beneath the email textbox once that box is filled. I could give you the code if you can post the code over here
Replace the controls ids in this answer as per your html.
You can show the confirm controls in the following way.
$('#password').onfocusout(function() {
// This will show once you complete entering Email and Password.
$('#confirmEmail').attr('display', 'inline');
$('#confirmPassword').attr('display', 'inline');
});
Let me tell how you can achieve confirm Email. Same thing can be used to achieve confirm password.
When you focus out of confirm email textbox compare the emails entered by the user in Email and Confirm Email textboxex.
This can be done in following way
$('#confirmEmail').onfocusout(function() {
if($('#confirmEmail').val() == $('#Email').val())
{
// Emails entered are same
}
else
{
alert('Emails entered are not matching. Please reenter emails.');
}
});
Similarly you can check for confirm password.

Asp.Net popup error message

Is there a way I can display an error message in a popup box? I'm using Asp.Net (C#), and on our webpage, if an order goes throug incorrectly we display an error message. Now, we would like to be able to do so using some sort of pop-up method (maybe Ajax?) - it should be able to take a string value to display the error message.
For a simple approach, you can have a script block that contains alert("your error message"). If you want the popup to be styled as the rest of your website then you could render your error message into a div element and use a jQuery dialog to display it as a modal dialog within your page.
I have used Ajax to accomplish this myself.
Using the ModalPopupExtender and setting the PopupControlID to an Asp Panel, I usually put this into a User Control so it can be easily used through a website.
However below is a snippet of the asp.net code
<div class="modalPopupAlign">
<asp:LinkButton ID="lnkConfirm" Style="display: none;" CausesValidation="false" runat="server" PostBackUrl="#">Confirm</asp:LinkButton>
<ajax:ModalPopupExtender ID="lnkConfirm_ModalPopupExtender" runat="server" TargetControlID="lnkConfirm" PopupControlID="pnlConfirmation" BackgroundCssClass="modalBackground" DropShadow="true" RepositionMode="None">
</ajax:ModalPopupExtender>
<div id="pnlConfirmation" class="modalPopup" style="display: none;">
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div class="modalPopupContainerAlign">
<div>
<asp:Image ID="imgIcon" CssClass="modalPopupImage" runat="server" />
<asp:Label ID="lblMessage" CssClass="modalPopupMessage" runat="server"></asp:Label>
<div class="modalPopupTextbox"><asp:TextBox ID="txtValue" Width="200px" MaxLength="100" Visible="false" runat="server"></asp:TextBox></div>
<asp:Button ID="btnAction" runat="server" CausesValidation="false" CssClass="defaultButton" Text="OK" />
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
It does take some time to get it working properly as I have had a few errors with the script manager, which I currently have setup in a master page.
Just might give you a direction to head for, and the CSS can help shape and colour the message box.
Although this is a complex way in some respect but has many uses.
You can do this with simple javascript like this...
alert("my error message");
Here is more info on using javascript

Categories

Resources