473,669 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Function w/ webcontrol as a pramater

Jon
I would like to pass a reference of a webcontrol into a javascript
function. Below I have a snippet of code. "me.selectedVal ue" returns
undefined. I was hoping that would return the value that the user has
selected in the radio list..

ps: this is my first post, be gentle:)

**aspx page**

<form id="Form1" method="post" runat="server">
<asp:RadioButto nList ID=radio1 Runat=server >
<asp:ListItem Value=1 >Option 1</asp:ListItem>
<asp:ListItem Value=2 >Option 2</asp:ListItem>
<asp:ListItem Value=3 >Option 3</asp:ListItem>
</asp:RadioButton List>
</form>

**Code Behind**
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim strScript As String = "<script language=""Java Script"">" &
vbCrLf
strScript += " function test1(me) " & vbCrLf
strScript += "{alert(me.Sele ctedValue); " & vbCrLf
strScript += "}</script>"

If (Not Page.IsClientSc riptBlockRegist ered("clientScr ipt"))
Then
Page.RegisterCl ientScriptBlock ("clientScript" , strScript)
End If
End Sub

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r
radio1.Attribut es.Add("onclick ", "test1(this )")
End Sub
Nov 18 '05 #1
5 1919
You have Me.Selected.Val ue inside quotes. You seem to be passing what you
would like to have as a variable as a string.

This might be clearer if you used a StringBuilder:

Imports System.Text
..
..
..

Dim sbldr As New StringBuilder
sbldr.Append("< script language=""Java Script"">") :
sbldr.Append(vb CrLf)
sbldr.Append(" function test1(me) ") : sbldr.Append(vb CrLf)
sbldr.AppendFor mat("{alert({0} ); {1}}</script>", Me.SelectedValu e,
vbCrLf)

"Jon" <jf***********@ hotmail.com> wrote in message
news:ef******** *************** ***@posting.goo gle.com...
I would like to pass a reference of a webcontrol into a javascript
function. Below I have a snippet of code. "me.selectedVal ue" returns
undefined. I was hoping that would return the value that the user has
selected in the radio list..

ps: this is my first post, be gentle:)

**aspx page**

<form id="Form1" method="post" runat="server">
<asp:RadioButto nList ID=radio1 Runat=server >
<asp:ListItem Value=1 >Option 1</asp:ListItem>
<asp:ListItem Value=2 >Option 2</asp:ListItem>
<asp:ListItem Value=3 >Option 3</asp:ListItem>
</asp:RadioButton List>
</form>

**Code Behind**
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim strScript As String = "<script language=""Java Script"">" &
vbCrLf
strScript += " function test1(me) " & vbCrLf
strScript += "{alert(me.Sele ctedValue); " & vbCrLf
strScript += "}</script>"

If (Not Page.IsClientSc riptBlockRegist ered("clientScr ipt"))
Then
Page.RegisterCl ientScriptBlock ("clientScript" , strScript)
End If
End Sub

Private Sub Page_PreRender( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.PreRende r
radio1.Attribut es.Add("onclick ", "test1(this )")
End Sub

Nov 18 '05 #2
Thank you for your quick response :)

I am currently working with VB. Is stringBuilder a C# object?

The javascript is now working. me.ID yields the objects ID and me.Value
yeilds the value for asp:TextBox and asp:DropDownLis t.

How do you get the selected values for the RadioButtonList and
CheckBoxList controls? Is there an easy way to do this or do you have
to do some wierd looping through the generated HTML table?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
You can retrieve selected values like this

String s = "Selected items:<br>"

for (int i=0; i < CheckBoxList1.I tems.Count; i++)

if ( CheckBoxList1.I tems[ i ].Selected )

// List the selected item
s = s + CheckBoxList1.I tems[i].Value
s = s + "<br>"
}

Label1my1.Text = s;
Nov 18 '05 #4
Stringbuilder is a .NET object, you can use it in VB.NET.

"Jon Turner" <jf***********@ hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
Thank you for your quick response :)

I am currently working with VB. Is stringBuilder a C# object?

The javascript is now working. me.ID yields the objects ID and me.Value
yeilds the value for asp:TextBox and asp:DropDownLis t.

How do you get the selected values for the RadioButtonList and
CheckBoxList controls? Is there an easy way to do this or do you have
to do some wierd looping through the generated HTML table?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5
Thank you Peter. I have tried your example, but can't seem to get it to
work. Below is a code snippet. I keep getting the error Message
"'check1.Items. Count' is null or not an object"

My goal is to get the sum total of the selected values. Then take that
number and perform a bitwise operation with another number. If returns
true - make a Div visible Else Hidden.
<script language="JavaS cript">
function test1()
{
for ( i=0; i < check1.Items.Co unt; i++)
{
if (check1.Items[i].Selected)
{
sValue = Svalue + check1.Items[i].Value;
}
}
alert(sValue);
}
</script>

*****

<asp:CheckBoxLi st ID=check1 Runat=server onclick="test1( );">
<asp:ListItem Selected=True Value=1>Option 1</asp:ListItem>
<asp:ListItem Value=2 >Option 2</asp:ListItem>
<asp:ListItem Value=4 >Option 3</asp:ListItem>
</asp:CheckBoxLis t>
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #6

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

Similar topics

0
1157
by: Gijs Korremans | last post by:
Hi, One of the functions in the com object I need to use has a pointer in one of it's functions (object.function(string input, struct * output)) (I've created the struct with win32com.client.Record("structure", object)) I've tried to use the id() function but then Python gives me a message thatit's an int, not a tructure and when I just give the object without a pointer, the object is still empty afterwards.
2
1680
by: Peregrin | last post by:
Hello world. I will try to explain my problem. I've a webcontrol with an interface which provides a choice of methods. After including the webcontrol in a special aspx page, I want to call an interface webcontrol method from a javascript function part of special aspx page. But I don't know how to call a public webcontrol method from a client side javascript function ? Thanks for response.
3
18804
by: Aamir Ghanchi | last post by:
Hi, I am wondering why the <%= % is not working when I use it to pass the clientid to a javascrip function from the aspx declaration code. Say, I have a listbox webcontrol and from its client-side javascript eventhandler attribute, I try to pass on the client id as follows <asp:ListBox ID="myListBox" runat="server" onchange="lst_onchange('< %=myListBox.ClientID%>')" >
18
4752
by: Dan | last post by:
Hi, There is a detailsview which contains a textbox in editmode. How to get the id of the textbox in javascript? I tried this: <asp:DetailsView ID="DetailsView1" runat="server" > <asp:TemplateField> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </EditItemTemplate>
0
8466
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8384
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
8896
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
8810
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
8659
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...
1
6211
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
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
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.