?
Solved

Losing Data on Verification

Posted on 2014-03-06
6
Medium Priority
?
251 Views
Last Modified: 2014-03-08
Dear Experts,
I have a text box that counts down allowed number of words. Before the contributor can submit the article they have to agree to the submission policy. The agreement checkbox is validated. If it is unchecked at submission the validation posts the error so the author can agree and submit their article. Only one problem. On the post back of the submit button it clears out the text box of the article the author had just spent so much time typing in.

What I need is the textbox not to clear  if the page is invalid. Below is the code for the html and for the C# asp.net on the code behind. Can you tell me how to make it happen?

Thanks,
Bob Bellows

HTML:
    <textarea id="FaithStory" cols="60" rows="9"></textarea>

    <div id="Submission" 
        
        
        style="position: absolute; width: 479px; height: 36px; top: 188px; left: 42px; text-align: left; font-size: medium;">
    
        <asp:CheckBox ID="ckbxAgreeSubmissionPolicy" runat="server" Text="I agree to the Submission Policy of I-CollaborateInc.com" />
        <asp:CustomValidator ID="CustomValidator1" runat="server" 
            ErrorMessage="You must agree to the Submission Policy" 
            onservervalidate="CustomValidator1_ServerValidate">*</asp:CustomValidator>
        <br />
        <asp:HyperLink ID="HyperLink1" runat="server" Font-Names="Niamey" 
            Font-Size="Small" ForeColor="Blue" 
            NavigateUrl="http://www.i-collaborateinc.com/SubmissionPolicy.aspx" 
            Target="_blank">Submission Policy</asp:HyperLink>
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />    
     
    </div>
    <div style="position: absolute; width: 115px; height: 62px; top: 190px; left: 619px;">
    <asp:Button ID="btnSubmitFaithStory" runat="server" Text="Submit" />
    </div>

Open in new window


c#

public partial class _hbiyg_FaithStories_AddYourStory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        args.IsValid=false;
        if (ckbxAgreeSubmissionPolicy.Checked)
            args.IsValid=true;
    }
 
}

Open in new window

0
Comment
Question by:bobbellows
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39912055
You'll need to turn your textarea into a server control and enable viewstate:
<textarea id="FaithStory" runat="server" enableviewstate="true" cols="60" rows="9"></textarea>

Open in new window

0
 

Author Comment

by:bobbellows
ID: 39912118
That kept the text in the textarea from losing it's text but by going to the server it lost the word counting function.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39912125
The code you posted doesn't show how your word counting works, but assuming it is a javascript function, you simply need to spit out a line of javascript after postback to call that again and have it recount the words.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:bobbellows
ID: 39912234
Sorry. You're right. I forgot about the jquery plugin.  

I'm sorta new to this and had another expert help me create the textarea with word counting. That was my first experience working with jquery and I know very little about java script.

Here is the code for the jquery. It's on a master page if that makes a difference.

jquery

<link href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.min.js"></script>
<script type="text/javascript" src="../JS/word-and-character-counter.js"></script>

<script>
$(function() {
  $("#FaithStory").counter({
    type: 'word', 
    goal: 250
});
});
</script>

Open in new window

0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 39912341
You will probably need to move the javascript to the WebForm itself. When you switch the textarea to be a server control, the ID will be generated at runtime by the ASP.Net engine, and you will need that ID for the javascript.

So, move this:
<script>
$(function() {
  $("#FaithStory").counter({
    type: 'word', 
    goal: 250
});
});
</script>

Open in new window

To your WebForm and put it somewhere towards the bottom of the page. Then change:
$("#FaithStory").counter({

Open in new window

To:
$("#<%= FaithStory.ClientID %>").counter({

Open in new window

That will inject the auto generated ID into the script, and allow it to be re-applied after postback.
0
 

Author Closing Comment

by:bobbellows
ID: 39915344
Decided to create a page without the master page and this worked! Thanks!!
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question