hi....plese use this here use can define a value in codebehind and call javascript from codebehind and u can use hidden field to store value and from this from javascript ...check this ...tested as well....
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="javascript.aspx.vb" Inherits="javascript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script>
function display1(parameter)
{
var txtbox=document.getElementById(parameter);
alert(txtbox.value);
}
function display(parameter)
{
alert(parameter);
}
function display_hidden()
{
var txtbox=document.getElementById("HiddenField1");
alert(txtbox.value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="display1('TextBox1');" />
<asp:Button ID="Fromcodebehind" runat="server" Text="Button" />
<asp:Button ID="Hiddenfield" runat="server" Text="Button" OnClientClick="display_hidden();" />
<asp:HiddenField ID="HiddenField1" runat="server" />
</div>
</form>
</body>
</html>
Partial Class javascript
Inherits System.Web.UI.Page
Protected Sub Fromcodebehind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Fromcodebehind.Click
Dim count As Integer
count = 10
'call javascript from codebehind
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "display", "display('" & count & "')", True)
'or u can stroe this into hidden field and use in javascript
HiddenField1.Value = count
End Sub
End Class
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="javascript.aspx.vb" Inherits="javascript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script>
function display_hidden()
{
var txtbox=document.getElementById("HiddenField1");
alert(txtbox.value);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="SET_HIDDEN_VALUE" runat="server" Text="Set hidden value" />
<asp:Button ID="Hiddenfield_Button" runat="server" Text="Display hidden value" OnClientClick="display_hidden();" />
<asp:HiddenField ID="HiddenField1" runat="server" />
</div>
</form>
</body>
</html>
Partial Class javascript
Inherits System.Web.UI.Page
Protected Sub SET_HIDDEN_VALUE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SET_HIDDEN_VALUE.Click
Dim count As Integer
count = 10
HiddenField1.Value = count
'or
' HiddenField1.Value = textbox1.text
End Sub
End Class
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
A.Venkatesan
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Smadhu
Member
510 Points
989 Posts
how can i use vb.net varaible in javscript
Feb 19, 2012 04:57 AM|LINK
how can i use vb.net varaible in javscript
in backend i have defined variable count
how can i use that in javascript
Ruchira
All-Star
43062 Points
7043 Posts
MVP
Re: how can i use vb.net varaible in javscript
Feb 19, 2012 04:58 AM|LINK
Not a VB person. But I think you can access it if you define it as a public, global variable.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.Smadhu
Member
510 Points
989 Posts
Re: how can i use vb.net varaible in javscript
Feb 19, 2012 05:02 AM|LINK
Ruchira
All-Star
43062 Points
7043 Posts
MVP
Re: how can i use vb.net varaible in javscript
Feb 19, 2012 05:14 AM|LINK
variable Count should be public and definie it as a class variable.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.Smadhu
Member
510 Points
989 Posts
Re: how can i use vb.net varaible in javscript
Feb 19, 2012 05:27 AM|LINK
its is public only still its not working
venkatmca008
Participant
1810 Points
341 Posts
Re: how can i use vb.net varaible in javscript
Feb 19, 2012 05:32 AM|LINK
hi....plese use this here use can define a value in codebehind and call javascript from codebehind and u can use hidden field to store value and from this from javascript ...check this ...tested as well....
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="javascript.aspx.vb" Inherits="javascript" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script> function display1(parameter) { var txtbox=document.getElementById(parameter); alert(txtbox.value); } function display(parameter) { alert(parameter); } function display_hidden() { var txtbox=document.getElementById("HiddenField1"); alert(txtbox.value); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="display1('TextBox1');" /> <asp:Button ID="Fromcodebehind" runat="server" Text="Button" /> <asp:Button ID="Hiddenfield" runat="server" Text="Button" OnClientClick="display_hidden();" /> <asp:HiddenField ID="HiddenField1" runat="server" /> </div> </form> </body> </html> Partial Class javascript Inherits System.Web.UI.Page Protected Sub Fromcodebehind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Fromcodebehind.Click Dim count As Integer count = 10 'call javascript from codebehind ScriptManager.RegisterStartupScript(Me, Me.GetType(), "display", "display('" & count & "')", True) 'or u can stroe this into hidden field and use in javascript HiddenField1.Value = count End Sub End ClassMicrosoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Smadhu
Member
510 Points
989 Posts
Re: how can i use vb.net varaible in javscript
Feb 19, 2012 05:46 AM|LINK
in javascript:
var counter = document.getElementById("HiddenField1");
but variable is having null value ??????????
check out my code
in body:
<asp:HiddenField ID="HiddenField1" runat="server" />
in vb.net
Count = ds.Tables(1).Rows.Count
HiddenField1.Value = Count
venkatmca008
Participant
1810 Points
341 Posts
Re: how can i use vb.net varaible in javscript
Feb 19, 2012 05:56 AM|LINK
First set a hidden field .....value
in page load or some events
then call the javascript
.............
as my solution and i tested also......
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="javascript.aspx.vb" Inherits="javascript" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script> function display_hidden() { var txtbox=document.getElementById("HiddenField1"); alert(txtbox.value); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="SET_HIDDEN_VALUE" runat="server" Text="Set hidden value" /> <asp:Button ID="Hiddenfield_Button" runat="server" Text="Display hidden value" OnClientClick="display_hidden();" /> <asp:HiddenField ID="HiddenField1" runat="server" /> </div> </form> </body> </html> Partial Class javascript Inherits System.Web.UI.Page Protected Sub SET_HIDDEN_VALUE_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SET_HIDDEN_VALUE.Click Dim count As Integer count = 10 HiddenField1.Value = count 'or ' HiddenField1.Value = textbox1.text End Sub End ClassMicrosoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
venkatmca008
Participant
1810 Points
341 Posts
Re: how can i use vb.net varaible in javscript
Feb 19, 2012 05:58 AM|LINK
If u had still problem ....please let me know...
Microsoft Certified Professional
Please mark the replies as answers if they help or unmark if not.
If you have any feedback about my replies, please contact venkatmca008@gmail.com
Smadhu
Member
510 Points
989 Posts
Re: how can i use vb.net varaible in javscript
Feb 19, 2012 06:04 AM|LINK
vb.net code Public Class EditResources Inherits System.Web.UI.Page Public LastTextBoxId As String Public Count As Integer Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim id As Integer = Request.QueryString("Id") Dim ds As New DataSet() ds = ResourcesHelper.GetResourcesValueById(id) Dim dt1 As DataTable = ds.Tables(0) Dim dt2 As DataTable = ds.Tables(1) Count = ds.Tables(1).Rows.Count HiddenField1.Value = Count For i = 0 To Count - 1 Dim myTextBox = New TextBox myTextBox.ID = "colorpickerField" & i + 1 LastTextBoxId = myTextBox.ID myTextBox.CssClass = "cs_color" Dim ColorName As String = "#" & ds.Tables(1).Rows(i).Item(2) myTextBox.BackColor = System.Drawing.ColorTranslator.FromHtml(ColorName) Me.ColorPickerDiv.Controls.Add(myTextBox) MinusImageDiv.Controls.Add(HtmlHelper.GetLiteral(" <div class='cs_minus_div' id=Img-" & LastTextBoxId & "' >")) MinusImageDiv.Controls.Add(HtmlHelper.GetLiteral("<img src='Images\Icons\minus.png' class='cs_minusimg' />")) MinusImageDiv.Controls.Add(HtmlHelper.GetLiteral(" </div>")) Next UploadImgSec.Controls.Add(HtmlHelper.GetLiteral("<div id='cs_sec' >")) UploadImgSec.Controls.Add(HtmlHelper.GetLiteral("<img src='/Images/Resources/" & ds.Tables(0).Rows(0).Item(3) & "' CssClass='cs_img' width=120px height=73px ' />")) UploadImgSec.Controls.Add(HtmlHelper.GetLiteral(" </div>")) UploadImgSec2.Controls.Add(HtmlHelper.GetLiteral("<div id='cs_sec2' >")) UploadImgSec2.Controls.Add(HtmlHelper.GetLiteral("<img src='/Images/Resources/" & ds.Tables(0).Rows(0).Item(4) & "' CssClass='cs_img' width=120px height=73px ' />")) UploadImgSec2.Controls.Add(HtmlHelper.GetLiteral(" </div>")) If Not IsPostBack Then MultiView1.SetActiveView(View1) ResourcesId.Value = id txbResourcesTitle.Text = ds.Tables(0).Rows(0).Item(1) txbResourcesDimension.Text = ds.Tables(0).Rows(0).Item(2) 'DropdownCatogary.SelectedValue = ds.Tables(0).Rows(0).Item(5) End If End Sub javascript: $(document).ready(function () { var counter = document.getElementById("HiddenField1"); alert(counter); $("#addButton").click(function () { if (counter > 5) { alert("Only 10 textboxes allow"); return false; } var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter + "class", 'NewTextBoxDiv'); newTextBoxDiv.appendTo("#ctl00_InnerContent_ColorPickerDiv"); newTextBoxDiv.after('<label> </label>' + '<input type="text" id="colorpickerField' + counter + '" class="cs_color" />'); newTextBoxDiv.after(' <img src="Images\Icons\minus.png" /> '); counter++; }); $("#removeButton").click(function () { if (counter == 1) { alert("No more textbox to remove"); return false; } counter--; $("#TextBoxDiv" + counter).remove(); }); $("#getButtonValue").click(function () { var msg = ''; for (i = 1; i < counter; i++) { msg += "\n Textbox #" + i + " : " + $('#textbox' + i).val(); } alert(msg); }); }); aspx body code: <asp:HiddenField ID="HiddenField1" runat="server" /> <img src="Images/Icons/plus1.png" id="addButton" alt="addbox" /> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel runat="server" ID="UpdateColorPanel"> <ContentTemplate> <div class="wrappercolor" id="ColorPickerDiv" runat="server"> <div id="MinusImageDiv" runat="server"></div> </div> </ContentTemplate> </asp:UpdatePanel>ya still its not wroking for me