473,503 Members | 9,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Injecting javascript into a particular part in a page from inside a codebehind file.

How do you add javascript to a page from codebehind? I have a method I am
working on that has a few conditions in it:

1. if either 1 or both WordTextBox or DefinitionTextBox is empty, show a
popup window telling the user that the textbox(s) can't be empty and return
them to the page with no further action.
2. The value in WordTextBox is already in the collection as a key, so show a
popup telling the user that the word already exists and then return them to
the page with no further action.

How would you do this?

Jun 27 '08 #1
4 1205
On Apr 25, 7:19*pm, "Andy B" <a_bo...@sbcglobal.netwrote:
How do you add javascript to a page from codebehind? I have a method I am
working on that has a few conditions in it:

1. if either 1 or both WordTextBox or DefinitionTextBox is empty, show a
popup window telling the user that the textbox(s) can't be empty and return
them to the page with no further action.
2. The value in WordTextBox is already in the collection as a key, so showa
popup telling the user that the word already exists and then return them to
the page with no further action.

How would you do this?
1. I think you can do this with ASP.NET RequiredFieldValidator &
ValidationSummary Controls
2. How do you get collection? Is it a database value?
Jun 27 '08 #2
collection is a dictionary<strin, string>

"Alexey Smirnov" <al************@gmail.comwrote in message
news:a5**********************************@s50g2000 hsb.googlegroups.com...
On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglobal.netwrote:
How do you add javascript to a page from codebehind? I have a method I am
working on that has a few conditions in it:

1. if either 1 or both WordTextBox or DefinitionTextBox is empty, show a
popup window telling the user that the textbox(s) can't be empty and
return
them to the page with no further action.
2. The value in WordTextBox is already in the collection as a key, so show
a
popup telling the user that the word already exists and then return them
to
the page with no further action.

How would you do this?
1. I think you can do this with ASP.NET RequiredFieldValidator &
ValidationSummary Controls
2. How do you get collection? Is it a database value?
Jun 27 '08 #3
/*
How to validate two textboxes to ensure only one textbox contains data. Copy
and paste into Visual Studio for best results reading and comprehending how
this solution may be helpful to learn from...

*/

<%-- CUSTOM VALIDATOR --%>
<asp:CustomValidator
ID="ManagingEditorValidator" runat="server"
EnableViewState="false"
OnServerValidate="ManagingEditorTextBoxes_CustomVa lidator"
ErrorMessage="" />
// CustomValidator raises this event...
#region Validation: ManagingEditorTextBoxes_CustomValidator...
protected void ManagingEditorTextBoxes_CustomValidator(object
source, ServerValidateEventArgs args)
{
if (ChannelManagingEditorEmailTextBox.Text.Length 0 &&
ChannelManagingEditorNameTextBox.Text.Length 0)
{
args.IsValid = false;
ManagingEditorValidationLabel.Text = "<span
style='color:red;font-weight:bold;'>Only one TextBox may contain
data.</span>";
ChannelBuilderWizard.ActiveStepIndex = 5; //
Step5_ChannelManagingEditor
}
else
{
args.IsValid = true;
ManagingEditorValidationLabel.Text = "-- or --";
}
}//protected void ManagingEditorTextBoxes_CustomValidator(object
source, ServerValidateEventArgs args)
#endregion

/*
I also used the OnActiveStepChanged event of a Wizard control to determine
when to call a ValidateManagingEditorOrWebmasterTextBoxes() method
that --also-- modifies the ManagingEditorValidationLabel I have mentioned.
You can figure out where to call the method once you study and learn how
this example of server-side validation works.
*/
#region Validation: ValidateManagingEditorOrWebmasterTextBoxes...
// Both ManagingEditor and Webmaster steps display a set of
TextBoxes; one for email and another for a name
// but only one TextBox may be used to submit data.
// ChannelBuilderWizard_OnActiveStepChanged calls this method when
selecting the Wizard's Next button.
// ManagingEditorTextBoxes_CustomValidator and
WebmasterTextBoxes_CustomValidator are called when SideBar LinkButtons are
selected.
protected void ValidateManagingEditorOrWebmasterTextBoxes()
{
if (ChannelManagingEditorEmailTextBox.Text.Length 0 &&
ChannelManagingEditorNameTextBox.Text.Length 0)
{
ManagingEditorValidationLabel.Text = "<span
style='color:red;font-weight:bold;'>Only one TextBox may contain
data.</span>";
ChannelBuilderWizard.ActiveStepIndex = 5;
}
else if (ChannelWebmasterEmailTextBox.Text.Length 0 &&
ChannelWebmasterNameTextBox.Text.Length 0)
{
WebmasterValidationLabel.Text = "<span
style='color:red;font-weight:bold;'>Only one TextBox may contain
data.</span>";
ChannelBuilderWizard.ActiveStepIndex = 6;
}
else
{
if
(String.IsNullOrEmpty(ChannelManagingEditorEmailTe xtBox.Text.ToString()) ||
String.IsNullOrEmpty(ChannelManagingEditorNameText Box.Text.ToString()))
{
ManagingEditorValidationLabel.Text = "-- or --";
}
if
(String.IsNullOrEmpty(ChannelWebmasterEmailTextBox .Text.ToString()) ||
String.IsNullOrEmpty(ChannelWebmasterNameTextBox.T ext.ToString()))
{
WebmasterValidationLabel.Text = "-- or --";
}
}
}//ValidateManagingEditorAndWebmasterTextBoxes()
#endregion

<%= Clinton Gallagher
"Andy B" <a_*****@sbcglobal.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
collection is a dictionary<strin, string>

"Alexey Smirnov" <al************@gmail.comwrote in message
news:a5**********************************@s50g2000 hsb.googlegroups.com...
On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglobal.netwrote:
>How do you add javascript to a page from codebehind? I have a method I am
working on that has a few conditions in it:

1. if either 1 or both WordTextBox or DefinitionTextBox is empty, show a
popup window telling the user that the textbox(s) can't be empty and
return
them to the page with no further action.
2. The value in WordTextBox is already in the collection as a key, so
show a
popup telling the user that the word already exists and then return them
to
the page with no further action.

How would you do this?

1. I think you can do this with ASP.NET RequiredFieldValidator &
ValidationSummary Controls
2. How do you get collection? Is it a database value?
Jun 27 '08 #4
This wasn't exactly what I was looking for. I need to have a popup window
(the javascript alert window) pop up if:

1. The WordTextBox.Text property is empty.
2. The DefinitionTextBox.Text property is empty.
3. Both WordTextBox.Text and DefinitionTextBox.Text are empty at the same
time.
4. The value for WordTextBox.Text already exists inside the dictionary
collection.

Of course all of these have different messages that go along with them.
"clintonG" <no****@nowhere.comwrote in message
news:Oo**************@TK2MSFTNGP04.phx.gbl...
/*
How to validate two textboxes to ensure only one textbox contains data.
Copy and paste into Visual Studio for best results reading and
comprehending how this solution may be helpful to learn from...

*/

<%-- CUSTOM VALIDATOR --%>
<asp:CustomValidator
ID="ManagingEditorValidator" runat="server"
EnableViewState="false"
OnServerValidate="ManagingEditorTextBoxes_CustomVa lidator"
ErrorMessage="" />
// CustomValidator raises this event...
#region Validation: ManagingEditorTextBoxes_CustomValidator...
protected void ManagingEditorTextBoxes_CustomValidator(object
source, ServerValidateEventArgs args)
{
if (ChannelManagingEditorEmailTextBox.Text.Length 0 &&
ChannelManagingEditorNameTextBox.Text.Length 0)
{
args.IsValid = false;
ManagingEditorValidationLabel.Text = "<span
style='color:red;font-weight:bold;'>Only one TextBox may contain
data.</span>";
ChannelBuilderWizard.ActiveStepIndex = 5; //
Step5_ChannelManagingEditor
}
else
{
args.IsValid = true;
ManagingEditorValidationLabel.Text = "-- or --";
}
}//protected void ManagingEditorTextBoxes_CustomValidator(object
source, ServerValidateEventArgs args)
#endregion

/*
I also used the OnActiveStepChanged event of a Wizard control to determine
when to call a ValidateManagingEditorOrWebmasterTextBoxes() method
that --also-- modifies the ManagingEditorValidationLabel I have mentioned.
You can figure out where to call the method once you study and learn how
this example of server-side validation works.
*/
#region Validation: ValidateManagingEditorOrWebmasterTextBoxes...
// Both ManagingEditor and Webmaster steps display a set of
TextBoxes; one for email and another for a name
// but only one TextBox may be used to submit data.
// ChannelBuilderWizard_OnActiveStepChanged calls this method when
selecting the Wizard's Next button.
// ManagingEditorTextBoxes_CustomValidator and
WebmasterTextBoxes_CustomValidator are called when SideBar LinkButtons are
selected.
protected void ValidateManagingEditorOrWebmasterTextBoxes()
{
if (ChannelManagingEditorEmailTextBox.Text.Length 0 &&
ChannelManagingEditorNameTextBox.Text.Length 0)
{
ManagingEditorValidationLabel.Text = "<span
style='color:red;font-weight:bold;'>Only one TextBox may contain
data.</span>";
ChannelBuilderWizard.ActiveStepIndex = 5;
}
else if (ChannelWebmasterEmailTextBox.Text.Length 0 &&
ChannelWebmasterNameTextBox.Text.Length 0)
{
WebmasterValidationLabel.Text = "<span
style='color:red;font-weight:bold;'>Only one TextBox may contain
data.</span>";
ChannelBuilderWizard.ActiveStepIndex = 6;
}
else
{
if
(String.IsNullOrEmpty(ChannelManagingEditorEmailTe xtBox.Text.ToString())
|| String.IsNullOrEmpty(ChannelManagingEditorNameText Box.Text.ToString()))
{
ManagingEditorValidationLabel.Text = "-- or --";
}
if
(String.IsNullOrEmpty(ChannelWebmasterEmailTextBox .Text.ToString()) ||
String.IsNullOrEmpty(ChannelWebmasterNameTextBox.T ext.ToString()))
{
WebmasterValidationLabel.Text = "-- or --";
}
}
}//ValidateManagingEditorAndWebmasterTextBoxes()
#endregion

<%= Clinton Gallagher
"Andy B" <a_*****@sbcglobal.netwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>collection is a dictionary<strin, string>

"Alexey Smirnov" <al************@gmail.comwrote in message
news:a5**********************************@s50g200 0hsb.googlegroups.com...
On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglobal.netwrote:
>>How do you add javascript to a page from codebehind? I have a method I
am
working on that has a few conditions in it:

1. if either 1 or both WordTextBox or DefinitionTextBox is empty, show a
popup window telling the user that the textbox(s) can't be empty and
return
them to the page with no further action.
2. The value in WordTextBox is already in the collection as a key, so
show a
popup telling the user that the word already exists and then return them
to
the page with no further action.

How would you do this?

1. I think you can do this with ASP.NET RequiredFieldValidator &
ValidationSummary Controls
2. How do you get collection? Is it a database value?

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

136
9201
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
2
2343
by: Christopher Ambler | last post by:
I'm wondering if there's a solution here - I have an ASPX page with a sole purpose of scaling an image. The ASPX page contains a single line with the codebehind tag, and the .cs file contains...
3
3675
by: Simon Harvey | last post by:
Hi All I am making a particular asp.net page using the codebehind method. What I need to do is write out html in the code behind into a specific place in the page. Somewhat like the way Servlets...
17
1551
by: Luke Matuszewski | last post by:
Hi ! Simple question (but thus it may appear no simple answer): If i putting a script onto the page i simply could inline it in <script> element or via its src attribute so (second way): <script...
8
3622
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
1
25620
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
2
1649
by: CrystalMikeMD | last post by:
Greetings, I've been at this problem for some time now and have decided to seek out some help. Essentially, this is what I have. A basic ASP.NET 2.0 page. On this page is the standard...
4
4230
by: archana | last post by:
Hi all, i am having one user control. what i want is to add javascript which will gets called on button click of user control. but user control is not working if i add javascript in user...
4
2688
by: =?Utf-8?B?R1ROMTcwNzc3?= | last post by:
Hi Guys, thanks for your help yesterday, I've got one more question, then I think I'm done for now,... Is it possible to insert recordset data in a javascript, for instance I have a javascript...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.