[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Losing Data on Verification

Posted on 2014-03-06
6
Medium Priority
?
254 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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.
Suggested Courses
Course of the Month17 days, 18 hours left to enroll

831 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