Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid CompareValidator or Javascript alert 2

Status
Not open for further replies.

ISPrincess

Programmer
Feb 22, 2002
318
US
I am having a major issue getting a working CompareValidator into Datagrid.

Here is some background

Say i have a grid with 3 columns.

Column1 = ItemNo
Column2 = TotalNumber
Column3 = AvailableNumber

The only editable (textbox) column is AvailableNumber.
I have a working RequiredFieldValidator against that field, but need a CompareValidator to compare AvailableNumber to TotalNumber to be sure that AvailableNumber is <= TotalNumber.

I have tried everything, but since the TotalNumber column is not editable and therefore is either an itemtemplate or databound column, I do not know what control or value to compare against. I have even tried placing the TotalNumber value into a sessionvariable on EditRow, but still the compare does not work.

If I cannot get a compare to work, then on the UpdateRow process, is there a way that I can just popup a javascript to tell the user "Available Number cannot be greater than Total"? I just dont know how to write the javascript inside the following if statement:

If iAvailableNumber > Session("TotalNumber") Then
javascript alert popup here
end if



PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
Here's how you would code that alert into your Update process, which is going to be your best route to solving this problem.

If iAvailableNumber > Session("TotalNumber") Then
dim script as string
script = "<script language=javascript>alert('Available Number cannot be greater than Total');</script>"
Page.RegisterStartupScript("error",script)
Exit Sub
end if

:)
paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Thank you - Perfect!

PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
Since your solution was so perfect, i was hoping that you (or anyone) wouldnt mind pointing me in the right direction for making the alert text a variable (strErrorMessage).

I am completely inexperience with Java, but in a sub routine (ValidateReturnValues), I fill a var: strErrorMessage if there was some sort of error or message I need to get back to the user. I would like that routine to simply return the value back and then display that value in this Java alert popup.

Possible? difficult?

Thank you again!

PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
Do you mean like this?
Code:
Dim strErrorMessage As String = "My Error Message"
If iAvailableNumber > Session("TotalNumber") Then
  dim script as string
  script = "<script language=javascript>alert(" & strErrorMessage & ");</script>"
  Page.RegisterStartupScript("error",script)
  Exit Sub
end if
Or did you want the error message as a javascript variable?

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
With this code:
Code:
Dim sErrormessage As String = "test"
Dim script As String
script = "<script language=javascript>alert(" & sErrormessage & ");</script>"
        Page.RegisterStartupScript("error", script)

I get a runtime error of:

Microsoft JScript runtime error: 'test' is undefined


and the runtime code is now:
Code:
<Script language=javascript>alert(test);

PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
You guys are making this WAY too hard.

Add a ValidationSummary control, and set the MessageBox property to true.

The only disadvantage is it will display ALL validation error messages.
 
I will try that. I am a newbie and just heard of the ValidationSummary a couple of days ago. Did not know it had a messagebox property!

Thanks for all your help.

PH
I was walking home one night and a guy hammering on a roof called me a paranoid little weirdo.
In morse code.
-Emo Phillips
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top