Solved

Losing Data on Verification

Posted on 2014-03-06
6
244 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
  • 3
  • 3
6 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:bobbellows
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
Decided to create a page without the master page and this worked! Thanks!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now