473,695 Members | 2,424 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 DefinitionTextB ox 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 1216
On Apr 25, 7:19*pm, "Andy B" <a_bo...@sbcglo bal.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 DefinitionTextB ox 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 RequiredFieldVa lidator &
ValidationSumma ry Controls
2. How do you get collection? Is it a database value?
Jun 27 '08 #2
collection is a dictionary<stri n, string>

"Alexey Smirnov" <al************ @gmail.comwrote in message
news:a5******** *************** ***********@s50 g2000hsb.google groups.com...
On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglo bal.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 DefinitionTextB ox 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 RequiredFieldVa lidator &
ValidationSumma ry 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:CustomVali dator
ID="ManagingEdi torValidator" runat="server"
EnableViewState ="false"
OnServerValidat e="ManagingEdit orTextBoxes_Cus tomValidator"
ErrorMessage="" />
// CustomValidator raises this event...
#region Validation: ManagingEditorT extBoxes_Custom Validator...
protected void ManagingEditorT extBoxes_Custom Validator(objec t
source, ServerValidateE ventArgs args)
{
if (ChannelManagin gEditorEmailTex tBox.Text.Lengt h 0 &&
ChannelManaging EditorNameTextB ox.Text.Length 0)
{
args.IsValid = false;
ManagingEditorV alidationLabel. Text = "<span
style='color:re d;font-weight:bold;'>O nly one TextBox may contain
data.</span>";
ChannelBuilderW izard.ActiveSte pIndex = 5; //
Step5_ChannelMa nagingEditor
}
else
{
args.IsValid = true;
ManagingEditorV alidationLabel. Text = "-- or --";
}
}//protected void ManagingEditorT extBoxes_Custom Validator(objec t
source, ServerValidateE ventArgs args)
#endregion

/*
I also used the OnActiveStepCha nged event of a Wizard control to determine
when to call a ValidateManagin gEditorOrWebmas terTextBoxes() method
that --also-- modifies the ManagingEditorV alidationLabel 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: ValidateManagin gEditorOrWebmas terTextBoxes...
// 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.
// ChannelBuilderW izard_OnActiveS tepChanged calls this method when
selecting the Wizard's Next button.
// ManagingEditorT extBoxes_Custom Validator and
WebmasterTextBo xes_CustomValid ator are called when SideBar LinkButtons are
selected.
protected void ValidateManagin gEditorOrWebmas terTextBoxes()
{
if (ChannelManagin gEditorEmailTex tBox.Text.Lengt h 0 &&
ChannelManaging EditorNameTextB ox.Text.Length 0)
{
ManagingEditorV alidationLabel. Text = "<span
style='color:re d;font-weight:bold;'>O nly one TextBox may contain
data.</span>";
ChannelBuilderW izard.ActiveSte pIndex = 5;
}
else if (ChannelWebmast erEmailTextBox. Text.Length 0 &&
ChannelWebmaste rNameTextBox.Te xt.Length 0)
{
WebmasterValida tionLabel.Text = "<span
style='color:re d;font-weight:bold;'>O nly one TextBox may contain
data.</span>";
ChannelBuilderW izard.ActiveSte pIndex = 6;
}
else
{
if
(String.IsNullO rEmpty(ChannelM anagingEditorEm ailTextBox.Text .ToString()) ||
String.IsNullOr Empty(ChannelMa nagingEditorNam eTextBox.Text.T oString()))
{
ManagingEditorV alidationLabel. Text = "-- or --";
}
if
(String.IsNullO rEmpty(ChannelW ebmasterEmailTe xtBox.Text.ToSt ring()) ||
String.IsNullOr Empty(ChannelWe bmasterNameText Box.Text.ToStri ng()))
{
WebmasterValida tionLabel.Text = "-- or --";
}
}
}//ValidateManagin gEditorAndWebma sterTextBoxes()
#endregion

<%= Clinton Gallagher
"Andy B" <a_*****@sbcglo bal.netwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
collection is a dictionary<stri n, string>

"Alexey Smirnov" <al************ @gmail.comwrote in message
news:a5******** *************** ***********@s50 g2000hsb.google groups.com...
On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglo bal.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 DefinitionTextB ox 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 RequiredFieldVa lidator &
ValidationSumma ry 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.Tex t property is empty.
2. The DefinitionTextB ox.Text property is empty.
3. Both WordTextBox.Tex t and DefinitionTextB ox.Text are empty at the same
time.
4. The value for WordTextBox.Tex t 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******** ******@TK2MSFTN GP04.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:CustomVali dator
ID="ManagingEdi torValidator" runat="server"
EnableViewState ="false"
OnServerValidat e="ManagingEdit orTextBoxes_Cus tomValidator"
ErrorMessage="" />
// CustomValidator raises this event...
#region Validation: ManagingEditorT extBoxes_Custom Validator...
protected void ManagingEditorT extBoxes_Custom Validator(objec t
source, ServerValidateE ventArgs args)
{
if (ChannelManagin gEditorEmailTex tBox.Text.Lengt h 0 &&
ChannelManaging EditorNameTextB ox.Text.Length 0)
{
args.IsValid = false;
ManagingEditorV alidationLabel. Text = "<span
style='color:re d;font-weight:bold;'>O nly one TextBox may contain
data.</span>";
ChannelBuilderW izard.ActiveSte pIndex = 5; //
Step5_ChannelMa nagingEditor
}
else
{
args.IsValid = true;
ManagingEditorV alidationLabel. Text = "-- or --";
}
}//protected void ManagingEditorT extBoxes_Custom Validator(objec t
source, ServerValidateE ventArgs args)
#endregion

/*
I also used the OnActiveStepCha nged event of a Wizard control to determine
when to call a ValidateManagin gEditorOrWebmas terTextBoxes() method
that --also-- modifies the ManagingEditorV alidationLabel 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: ValidateManagin gEditorOrWebmas terTextBoxes...
// 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.
// ChannelBuilderW izard_OnActiveS tepChanged calls this method when
selecting the Wizard's Next button.
// ManagingEditorT extBoxes_Custom Validator and
WebmasterTextBo xes_CustomValid ator are called when SideBar LinkButtons are
selected.
protected void ValidateManagin gEditorOrWebmas terTextBoxes()
{
if (ChannelManagin gEditorEmailTex tBox.Text.Lengt h 0 &&
ChannelManaging EditorNameTextB ox.Text.Length 0)
{
ManagingEditorV alidationLabel. Text = "<span
style='color:re d;font-weight:bold;'>O nly one TextBox may contain
data.</span>";
ChannelBuilderW izard.ActiveSte pIndex = 5;
}
else if (ChannelWebmast erEmailTextBox. Text.Length 0 &&
ChannelWebmaste rNameTextBox.Te xt.Length 0)
{
WebmasterValida tionLabel.Text = "<span
style='color:re d;font-weight:bold;'>O nly one TextBox may contain
data.</span>";
ChannelBuilderW izard.ActiveSte pIndex = 6;
}
else
{
if
(String.IsNullO rEmpty(ChannelM anagingEditorEm ailTextBox.Text .ToString())
|| String.IsNullOr Empty(ChannelMa nagingEditorNam eTextBox.Text.T oString()))
{
ManagingEditorV alidationLabel. Text = "-- or --";
}
if
(String.IsNullO rEmpty(ChannelW ebmasterEmailTe xtBox.Text.ToSt ring()) ||
String.IsNullOr Empty(ChannelWe bmasterNameText Box.Text.ToStri ng()))
{
WebmasterValida tionLabel.Text = "-- or --";
}
}
}//ValidateManagin gEditorAndWebma sterTextBoxes()
#endregion

<%= Clinton Gallagher
"Andy B" <a_*****@sbcglo bal.netwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>collection is a dictionary<stri n, string>

"Alexey Smirnov" <al************ @gmail.comwrote in message
news:a5******* *************** ************@s5 0g2000hsb.googl egroups.com...
On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglo bal.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 DefinitionTextB ox 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 RequiredFieldVa lidator &
ValidationSumm ary 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
9376
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
2
2353
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 the code to read an image, use GDI+ to scale it to a reasonable size, and emit the image directly (setting content-type on the response and spitting out the bytes for the image). What I'd love to do would be to eliminate the ASPX page and be able...
3
3681
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 work. I have a couple of questions I hope someone can help with: 1. Can I output html by doing something like Response.out.write("<b>"); and is this the best way to do it
17
1569
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 type="text/javascript" src="js/crossBrowserDegradationLib.js"> </script> , my question is simple What encoding should i use when writting my crossBrowserDegradationLib.js: a) should it be the same encoding like encoding of my web page (and the
8
3665
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
1
25677
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 bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that variable can only be used in that function. If you were to try to access that variable anywhere else in...
2
1658
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 <formtag. Under that, we have an UpdatePanel object where the rest of my partial rendering controls live. There is simply a basic control, such as a Literal or Label in the UpdatePanel. When a button is clicked on the page, I want to send out
4
4236
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 control.. but if i add javascript in page in which i am adding user control then that javascript is executed properly. i tested by displaying alert message in javascript. can anyone tell
4
2713
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 code that calculates the total price, depending on number of units, currently what the code does is set the price like so - if qty 1 then £99+VAT if qty equall to or greater than 2 and equall to or less than 9 then price =
0
8583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9002
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8833
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7673
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5841
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4349
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3021
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 we have to send another system
2
2283
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.