I'm trying to include both JS and C# so that if they disable the JS it will not allow them to submit - and give them an error message. Disabling the button is a good idea - and I'm going to now include that - but I still need to figure out the backend and how to keep the text value of the label.

Hello,

In a label, I am displaying the number of characters left in a textbox. Once the user goes into negative characters remaining, the label text turns red. If they try to submit the form, an alert message will popup letting them know they have exceeding the limit of characters. I am not sure how to store the state(text and color) of the label so that after the button click, when the page reloads, it will go back to what it was. Everytime it reloads, it goes back to "500 Characters Remaining" - which is the limit I am setting. I have also tried the C# code below - putting in the JS call in the Page_Load - but it is not working either. Any help would be great!

<script type="text/javascript">
    function CharCounter() {

        var textBox = document.getElementById('<%=lblCharCount.ClientID%>');
        var label = document.getElementById('<%=txtResDesc.ClientID%>');
        var charCount = 500 - textBox.value.length;
        label.innerHTML = charCount + " Characters Remaining.";
        if (charCount >= 0) {
            //within limit - display in black
           label.style.color = "black";
        }
        else {
            //negative chars - display in red
            label.style.color = "red";
        }
    }

    function charCountAlert() {
        var textBox = document.getElementById('<%= txtResDesc.ClientID%>');
        var charCount = textBox.value.length;
        if (charCount > 500) {
            alert("Error: Cannot submit Research Description with more than 500 characters.");
        }
    }
</script>

<asp:Label ID="lblCharCount" runat="server"/>
<asp:TextBox ID="txtResDesc" runat="server" Height="53px" TextMode="MultiLine" Width="90%" onkeyup="CharCounter()"></asp:TextBox>
<asp:Label ID="lblSubmitError" CssClass="redText" runat="server" />
<asp:Button ID="btnSubmitResearchDesc" runat="server" Text="Submit" Font-Bold="true" OnClientClick="return charCountAlert();"/>

//C# file
protected void Page_Load(object sender, EventArgs e)
{  
    if (!Page.ClientScript.IsStartupScriptRegistered("charCounter"))
    {
        Page.ClientScript.RegisterStartupScript((this.GetType()), "charCounter", "charCounter();", ...

Hello,

I am trying to incorporate Javascript with ASP. I want to display in the Label how many characters the client has remaining in the textbox. The Label is not changing at all - any ideas?

<script type="text/javascript">
    function CheckCharCount(textBox, maxLength) {
        var charCount = maxLength - texBox.value.length;
        document.getElementById("lblCharCount").innerText = ";
        if (charCount >= 0) {
            //within limit - display in black
            document.getElementById("lblCharCount").style.color = "black";
        }
        else {
            //negative chars - display in red
            document.getElementById("lblCharCount").style.color = "red";
        }
    }
</script>

<form runat="server">
<div>
    <asp:Label ID="lblCharCount" runat="server">500 Characters Remaining</asp:Label>
    <asp:TextBox ID="textBox" runat="server" Height="53px" TextMode="MultiLine" onkeyup="CheckCharCounter(this, 500)"/>
</div>
</form>

Thanks,

Brittany

That has worked. Thanks.

Oh okay. I see what you are saying. I'm new to ASP.NET - so thanks for pointing that out. I see in the source code that it turns the List into a table. It is still including the CSS Style I created though. Could the problem be because instead of saying "Class" it says "CSSClass" and therefore not picking it up? If this is correct - then how can I remedy this. Should I just put in "Class"?

Thanks.

<table id="ctl00_m_g_bed492a8_0da8_4869_af5e_ed578903ff20_ctl00_RequestOptions" class="radioButtonList" border="0">
    <tr>
        <td><span CSSClass="radioButtonList"><input id="ctl00_m_g_bed492a8_0da8_4869_af5e_ed578903ff20_ctl00_RequestOptions_0" type="radio" name="ctl00$m$g_bed492a8_0da8_4869_af5e_ed578903ff20$ctl00$RequestOptions" value="0" /><label for="ctl00_m_g_bed492a8_0da8_4869_af5e_ed578903ff20_ctl00_RequestOptions_0"><b>Transfer a material from the NIH</b><br/><span class="indenting"><em>Select this option if the NIH will <b>transfer</b> a material to an external organization</em></span></label></span></td>
    </tr>
    <tr>
        <td><span CSSClass="radioButtonList"><input id="ctl00_m_g_bed492a8_0da8_4869_af5e_ed578903ff20_ctl00_RequestOptions_1" type="radio" name="ctl00$m$g_bed492a8_0da8_4869_af5e_ed578903ff20$ctl00$RequestOptions" value="1" /><label for="ctl00_m_g_bed492a8_0da8_4869_af5e_ed578903ff20_ctl00_RequestOptions_1"><b>Transfer a material to the NIH</b><br/><span class="indenting"><em>Select this option if the NIH will <b>receive</b> a material from an external organization</em></span></label></span></td>
    </tr>
</table>

Hello,

I am trying to enlarge the font-size of an ASP:ListItem object using CSS. I have tried a few different ways - but it is not rendering. Any ideas on what would cause the ListItem to not pick up the CSS?

First try: CSSClass="radioButtonList" under asp:RadioButtonList

<style type="text/css"> 
    .radioButtonList
    {
        font-size:10em;
    }
    .indenting
    {
        padding-left: 40px;
    }
</style>

<asp:RadioButtonList ID="RequestOptions" CSSClass="radioButtonList" runat="server">
    <asp:ListItem Value="0">Hello World<br/><span class="indenting">World</span></asp:ListItem>
    <asp:ListItem Value="1">Hello Again<br/><span class="indenting">Again</span></asp:ListItem>
</asp:RadioButtonList>

Second try: CSSClass="radioButtonList" under asp:ListItem

    <style type="text/css"> 
        .radioButtonList
        {
            font-size:10em;
        }
        .indenting
        {
            padding-left: 40px;
        }
    </style>

    <asp:RadioButtonList ID="RequestOptions" runat="server">
        <asp:ListItem Value="0" CSSClass="radioButtonList">Hello World<br/><span class="indenting">World</span></asp:ListItem>
        <asp:ListItem Value="1" CSSClass="radioButtonList">Hello Again<br/><span class="indenting">Again</span></asp:ListItem>
    </asp:RadioButtonList>

A few thoughts...

Is CSSClass an allowed attribute of ListItem? When not used in conjunction with Sharepoint, what is the normal way to change the layout of individual ListItems? Could Sharepoint be causing this error?

Thanks,

Brittany

Thank you :)

The only problem I'm having now is more of a cosmetic issue. When I output my matrices, even though it outputs 0.00, I think in some cases it's not exactly 0. Because, some of them output as -0.00. Is there a way to fix this issue? Should I worry about actually making those values equal to 0?

Hey,

I am writing a program that takes the size of an nxn matrix [A], randomly creates that matrix, as well as an nx1 matrix [S], multiplies them together to create [A][S]=[B].
Then, using Gaussian Elimination, I use matrix [A] and [B] to find [x] such that [A]
[x]=[B].

I can see that I am not going about my algorithm the right way for this, and if anyone has some insight on what may be going wrong, I would appreciate it. I can tell based on the fact that [x] and [S] are not even a smidge close to each other.

I'm going to copy the entire code below so that it can be run.

Thanks :)

[CODE]

include <stdlib.h>
include <iostream>
include <iomanip>
include <fstream>
include <cmath>
include <new>
include <time.h>

using namespace std;

//aCtr and mCtr are used for analysis assignment
int aCtr = 0;
int mCtr = 0;

//double* make2DMatrix(int);
//double
make1DMatrix(int);
//double randomDouble();
//void fixDiagonals(double, int);
//void print2DMatrix(double
, int);
//void print1DMatrix(double*, int);

double make2DMatrix(int mat_size)
{
double
m;

m = new double* [mat_size];

for (int i = 0; i < mat_size; i++ )
{
    m[i] = new double[mat_size];
}
return m;

}

double make1DMatrix(int mat_size)
{
double
m;
m = new double[mat_size];
return m;
}

double randomDouble()
{
int randInt = rand() % 10001;
double randDouble = ((double)randInt) / 100.00;
return randDouble;
}

void fixDiagonals(double** &mat, int mat_size)
{
double temp;
for (int i = 0; i < mat_size; i++)
{
temp = 0;
for (int j ...

Thanks, this helps me out a lot. I appreciate it.
One question, I have never seen this:
[CODE]
Matrix(int m, int n)
: m(m), n(n)
[/CODE]

Which var is the one being passed into Matrix? The ones in the ()?

My Matrix class contains a 2D array right now. Everything works fine, but I'm trying to make it more efficient and a little neater. When I want to create a new matrix, I have to do

[CODE]
someMatrix.matrix[i,j];
[/CODE]

And was more or less looking to be able to do
[CODE]
someMatrix[i,j];
[/CODE]

Overloading the [ ] is a possibility, however I wanted to just check on the inheritance. Thanks though!

I've made a Matrix class that contains arrays, however I'd like to inherit the array class if possible. I've done some searching online and can't find any solid information on this. Does anyone know if I can even inherit this class? If so, do you have a good site with some reference info I can bookmark?

If anyone may have any other ideas on a container class to inherit for a Matrix class, feel free to share :)

Thanks,

Miss VavaZoom

Hey, thanks so much for helping me out! I really appreciate it...

This is my first program in C#, I've coded in C++ and Java, which makes it an easy transition. However, I'm still getting used to the C# way. Do I put the overloaded toString method in my matrix class, or as a function in the form?

Thank you!!

Alright, I took your advice, and initialized the matrix to 0 like the following, but still, no success

[CODE]
public static Matrix operator *(Matrix lhs, Matrix rhs)
{
Matrix temp = new Matrix();
temp.matrix = new double[lhs.getRow(), rhs.getCol()];
for (int i = 0; i < temp.row; i++)
for (int j = 0; j < temp.col; j++)
temp.matrix[i, j] = 0;

        for(int i = 0; i < lhs.getRow(); i++)
            for(int j = 0; j < rhs.getCol(); j++)
                for(int k = 0; k < lhs.getCol(); k++)
                    temp.matrix[i,j] += lhs.matrix[i,k] * rhs.matrix[k,j];
        return temp;
    }
}

[/CODE]

It still is not displaying in the textbox. I want to note that I have 2 other textboxes that are showing output of matrices using the display function I've created. I've corrected my algorithm to the following:

[CODE]
public static Matrix operator (Matrix lhs, Matrix rhs)
{
Matrix temp = new Matrix();
temp.matrix = new double[rhs.getRow(), rhs.getCol()];
for (int i = 0; i < lhs.getRow(); i++)
for (int j = 0; j < rhs.getCol(); j++)
for (int k = 0; k < lhs.getCol(); k++)
temp.matrix[i,j] += lhs.matrix[i,k]
rhs.matrix[k,j];
return temp;
}
[/CODE]

Yes, that's correct. And my multiline is set to true for my textbox.

I have a Matrix class and I am trying to overload the multiplication sign.
It compiles without error and runs, however it does not display the matrix like it should. So I want to make sure the error is not in my overload operation.

[CODE] public static Matrix operator (Matrix lhs, Matrix rhs)
{
Matrix temp = new Matrix();
temp.matrix = new double[rhs.getRow(), rhs.getCol()];
for (int i = 0; i < lhs.getRow(); i++)
{
for (int j = 0; j < lhs.getCol(); j++)
{
temp.matrix[i,0] += lhs.matrix[i,j]
rhs.matrix[j,0];
}
}
return temp;
}[/CODE]

This is my display function, so you can get an idea of what's going on
[CODE]
public string displayMatrix()
{
string display = "";
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
display += String.Format("{0,-15:00.00}", matrix[i, j]);
}
display += "\r\n";
}
return display;
}
[/CODE]

This is the code for the form to display it in the textbox
[CODE]
Matrix matrix_b = new Matrix();
matrix_b = matrix_A * matrix_s;
matrixBDisplay.Text = matrix_b.displayMatrix();
[/CODE]

Thanks for any help :)

-Miss Vavazoom

I am able to start a new thread for this question, however it pertains to the producer consumer problem I am working on, and am hoping you can still help.

I've finally gotten this to compile, however when I run it, I get the message:
Segmentation fault (core dumped)

I realize this has to do with memory. Is there a way to test where the problem is?

Thanks for the tips...I believe I am able to use the Queue class, however knowing how to implement my own is ideal.

Regarding the C or C++ issue. I'd like to keep it in C++, but if pthread.h is written in C, am I still able to compile in C++?

Thanks, that was really helpful. We do have to use pthreads, so I am looking into coding this in C instead of C++. I don't have any experience in C, but I'm assuming it's not terribly difficult to transition. One question about the buffer...After reading what you had to say, would it be smart then to use a queue and keep record of how many items are being placed in it up until a certain point, rather than an array of a particular size?

I'm working on a project that utilizes producers and consumers for an operating systems class. Each producer and each consumer will be its own thread. The producers will generate records that will be stored in a global buffer, in which the consumer will then access to use the data. I am having a hard time figuring out how to use actual pthreads. My original plan was to create a Producer class and a Consumer class and simulate the threads, but we are told now not to do so. Is there a c++ class for this? Also, for the buffer, I was initially creating an array of structs (the struct being the record created by the producer), but was now told I need to actually use Buffer. Are there any basic tutorials for this out there, or can someone shed some light on this topic on a good place to start.

Any help is appreciated :)

Thanks,

Miss VaVaZoom

Thanks :)

I'm trying to create a random float generator. The float must be 2 decimal places and between the values 0.50 and 999.99.

I tried casting rand() to a float below, which didn't work. I'd still like to know the reason this didn't work.
[CODE]
saleAmount = ((float)rand() % 99950.00 + 50.00 ) / 100.00;
[/CODE]

To make rand() a float with 2 decimal places, I did the following, which did work.
[CODE]
saleAmount = rand()*1.01;
[/CODE]

I've also tried using fmod, however I can't figure out how to get the outcome between the 2 boundaries.

Any suggestions or helpful tips?

Thanks,

Miss Vavazoom

Thanks, that helps a lot...will try it out!

What I failed to mention was not only dumping the buffer, but also only allocating enough space for the length of each line in the readFile.

I have 2 gigs of RAM at the moment. For partial reading, do you recommend deleting the buffer each time after dumping it into the writeFile?

[CODE]

include <iostream>
include <fstream>

using namespace std;

int main (int argc, char argv[])
{
int length;
char
buffer;

 string searchWord = argv[2];
 string compareStr;
 int searchSize = searchWord.size();

 ifstream readFile;
 readFile.open (argv[1], ios::in );
 ofstream writeFile;
 writeFile.open("newData.txt", ios::out);

 readFile.seekg (0, ios::end);
 length = readFile.tellg();
 readFile.seekg (0, ios::beg);

 buffer = new char [length];

 while(!readFile.eof())
 {    
      readFile.getline(buffer, length);
           compareStr = "";
           for (int i = 0; i < searchSize; ++i)
           {
                compareStr += buffer[i];
           }
           if (searchWord.compare(compareStr) == 0)
           {
                writeFile << buffer << "\n";
           }
 }    
 readFile.close();
 writeFile.close();
 delete[] buffer;
 return 0;

}
[/CODE]

I am running on Windows XP, and this program runs with test files (70 MB) just fine, but not with the much larger (1.5 GB) file. I get this error "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."

Any help would be appreciated! Thanks! :)

-MissVaVaZoom

I am trying to extract data from a 1.5 GB text file.
The problem occurs when the program tries to open the large text file.
It works perfectly on smaller files. Does anyone know how to successfully open a file of this size? Or, is there a better way to extract the data?

The objective is to go line by line, searching for a specific value in the first column of the data text file...and extracting the entire line...writing it to a new file.

Here is what I have:

[CODE]

include <iostream>
include <fstream>
include <string>

using namespace std;

const int MAXLINE = 256;

int main (int argc, char *argv[])
{
ifstream readFile (argv[1], ifstream::in);
ofstream writeFile ("extractedData.txt", ofstream::out);
char oneLine[MAXLINE];

 //Checks to see if the file opened successfully
 if ( !readFile.is_open() )
 {
      cout << "Could not open file\n";
 }
 else
 {
      string searchWord = argv[2];
      string compareStr;
      int searchSize = searchWord.size();
      while(!readFile.eof())
      {
           readFile.getline(oneLine, MAXLINE);
           compareStr = "";
           for (int i = 0; i < searchSize; ++i)
           {
                compareStr += oneLine[i];
           }
           if (searchWord.compare(compareStr) == 0)
           {
                writeFile << oneLine << "\n";
           }  
      }
 }
 readFile.close();
 writeFile.close();
 return 0;                

}
[/CODE]

Thanks in advance! :)

-Miss VaVaZoom

I am trying to extract data from a 1.5 GB text file.
The problem occurs when the program tries to open the large text file.
It works perfectly on smaller files. Does anyone know how to successfully open a file of this size? Or, is there a better way to extract the data?

The objective is to go line by line, searching for a specific value in the first column of the data text file...and extracting the entire line...writing it to a new file.

Here is what I have:

[CODE]

include <iostream>
include <fstream>
include <string>

using namespace std;

const int MAXLINE = 256;

int main (int argc, char *argv[])
{
ifstream readFile (argv[1], ifstream::in);
ofstream writeFile ("extractedData.txt", ofstream::out);
char oneLine[MAXLINE];

 //Checks to see if the file opened successfully
 if ( !readFile.is_open() )
 {
      cout << "Could not open file\n";
 }
 else
 {
      string searchWord = argv[2];
      string compareStr;
      int searchSize = searchWord.size();
      while(!readFile.eof())
      {
           readFile.getline(oneLine, MAXLINE);
           compareStr = "";
           for (int i = 0; i < searchSize; ++i)
           {
                compareStr += oneLine[i];
           }
           if (searchWord.compare(compareStr) == 0)
           {
                writeFile << oneLine << "\n";
           }  
      }
 }
 readFile.close();
 writeFile.close();
 return 0;                

}
[/CODE]

Thanks in advance! :)

-Miss VaVaZoom

I'm on a Fujitsu Lifebook T series, using Windows 7. I've just tried going through the disk defrager...and I do not see my local disk there. I've also tried right clicking on my C drive and going to the defrager via properties. Each time I only see the D drive.

I've been trying to defrag my local disk C, however it only shows the D drive. Even when I right click on C and get to the defrag via properties it shows D only.

Any suggestions?