You have to get the client ID of the object you are looking for. View Source on the page when it is running and you'll see the fully qualified Client ID which will be Container$ctl00$costLabel or something like that. Javascript doesn't FindControl on the
server, it's only looking at the client.
I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Your Label does not look as though it is in a GridView, but a Label on the client-side evaluates to a span tag, so you would not use the
value property. You would use the innerHTML property. Or:
var text = document.getElementById('<%= yourLabel.ClientID %>').innerHTML;
I now have no idea what you are trying to do. You have at least 3 threads dealing with the same problem, which is definitely a no-no.
I also see no GridView code anywhere in what you've posted. Please pick a thread, post the GridView code, and explain exactly what you are trying to achieve.
Do you have a master page with a content placeholder?
I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Partial Class box
Inherits System.Web.UI.Page
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Me.SqlDataSource4.SelectParameters(0).DefaultValue = 1
End Sub
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If Page.IsPostBack = True Then
Dim cost As Label = Me.FormView1.FindControl("costlabel")
Dim label As Label = Me.FormView1.FindControl("label1")
Dim pay As TextBox = Me.FormView1.FindControl("pay")
If Convert.ToInt32(cost.Text) > Convert.ToInt32(pay.Text) Then
Dim but As Button = FormView1.FindControl("button1")
Protected Sub FormView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles FormView1.ItemCommand
End Sub
Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cost As Label = Me.FormView1.FindControl("costlabel")
Dim label As Label = Me.FormView1.FindControl("label1")
Dim pay As TextBox = Me.FormView1.FindControl("pay")
Session("cost") = cost If Convert.ToInt32(cost.Text) < Convert.ToInt32(pay.Text) Then
label.Text = "your money is overloaded"
Else
If (HiddenField1.Value.ToLower() = "true") Then
Response.Write("your money is little")
Else
Response.Write("your money is small")
End If
End If
End Sub
End Class
the code in top is error textbox(pay)...
i want:
if i run page,it will display button. after click the button, it display formview. in formview is containning :
no order label(id:no_orderlabel)
cost label(id:costlabel)
pay textbox(id:pay)
click me(buton)
that pay(textbox) is manually i add it...
because in button2_click event use the code Me.SqlDataSource4.SelectParameters(0).DefaultValue = 1
so the first i click button, it will display data in formview with condition no order=1, like that:
no order 1
cost 10000
pay textbox(id:pay)
click me(buton)
so, i can input value to textbox. if i input 20000, it will display label "your money is overloaded"
if i input 200, it will display msgbox that have yes/no statement..
as long as i try and try again about code in top and change it, it can work but have problem like:
-can display msgbox, but in the second click.. the msgbox is late to display..
-can display msgbox at first click, but if i input 20000, it display msgbox and label. it should only display label..
so how to solve that problem?
i have try 30 hours for this...
the code in the top almost work,it's only error "format string....." at line textbox(pay). because i am using page.ispostback=true, the data in databound is firing the first before button1_click event fired. so it's to late to input value to textbox(pay),
so value in pay is empty, and it display error"format string...." i must use page.ispostback=true, so the msgbox is not late to show...
how should i do?
is there need change javascript or other event?
pls... thx...
Can you download the AJAX toolkit? There's a toolkit item that extends a textbox with a confirm dialog already built in.
It took me about 2 hours to get AJAX installed and running and then it's a piece of cake. Looks good on your resume too.
I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
I love to display the non-secure items...
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
hardy
Member
350 Points
477 Posts
how to pu the label from gridview to javascript?
Jan 22, 2008 04:10 PM|LINK
hello every one...
i have code like this:
<script language="javacsript" type="text/javascript">
function DisplayConfirmation()
{
var text = document.getElementById('<%=textbox1.ClientID%>').value;
if(confirm('your money is'+text+' are u want to send it?'))
{
document.getElementById('<%=HiddenField1.ClientID%>').value = "true"
}
else
{
document.getElementById("<%=HiddenField1.ClientID%>").value = 'false'
}
}
</script>
it can display msgbox with value textbox1..
but if i want to take value of label in gridview, how to put the label value from gridview to javascript?
my code like that:
var text = document.getElementById('<%=formview1.findcontrol("costLabel").ClientID%>').value;
but it's error "Object reference not set to an instance of an object."
my formview data:
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource4">
<ItemTemplate>
harga:
<asp:Label ID="costLabel" runat="server" Text='<%# Bind("cost") %>'></asp:Label><br />
no_order:
<asp:Label ID="no_orderLabel" runat="server" Text='<%# Bind("no_order") %>'></asp:Label><br />
<asp:Button CommandName="clicke" EnableTheming="True" ID="Button1" runat="server" Text="click me" OnClick="Button1_Click1" />
<asp:Label ID="Label1" runat="server"></asp:Label>
</ItemTemplate>
</asp:FormView>
what should i change it?
thx...
Charles Asbo...
Contributor
5512 Points
1186 Posts
Re: how to pu the label from gridview to javascript?
Jan 22, 2008 06:16 PM|LINK
You have to get the client ID of the object you are looking for. View Source on the page when it is running and you'll see the fully qualified Client ID which will be Container$ctl00$costLabel or something like that. Javascript doesn't FindControl on the server, it's only looking at the client.
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: how to pu the label from gridview to javascript?
Jan 22, 2008 11:06 PM|LINK
Your Label does not look as though it is in a GridView, but a Label on the client-side evaluates to a span tag, so you would not use the value property. You would use the innerHTML property. Or:
var text = document.getElementById('<%= yourLabel.ClientID %>').innerHTML;
In IE only, you could use the innerText property.
NC...
hardy
Member
350 Points
477 Posts
Re: how to pu the label from gridview to javascript?
Jan 23, 2008 04:16 PM|LINK
thx charles and nc...
so it can not use label/tetxbox from gridview in javascript... is the javascript only take html data?
ok, i have use label5 in html, so the value of costlabel in gridview is taken by label5 in html like this code:
dim cost as label=me.formview1.findcontrol("costlabel")
label5.text=cost.text
so in the javascript, i can put label5 to that...
ok, i have new problem that relation with this javascript...
http://forums.asp.net/p/1208084/2126979.aspx#2126979
pls... help if u want... it seem dificult...
but pls reply that problem in this thread...ok
many thx...
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: how to pu the label from gridview to javascript?
Jan 23, 2008 04:39 PM|LINK
I now have no idea what you are trying to do. You have at least 3 threads dealing with the same problem, which is definitely a no-no.
I also see no GridView code anywhere in what you've posted. Please pick a thread, post the GridView code, and explain exactly what you are trying to achieve.
NC...
Charles Asbo...
Contributor
5512 Points
1186 Posts
Re: how to pu the label from gridview to javascript?
Jan 23, 2008 04:42 PM|LINK
Do you have a master page with a content placeholder?
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
hardy
Member
350 Points
477 Posts
javascript and label is firing in the formview with condition..
Jan 24, 2008 02:40 AM|LINK
yes, i have master page with a content placeholder, but because my real project is have many code, so i make in testpage that no have masterpage.
sory, because my real project use formview, so in the testpage, i change the gridview to formview....
ok, i will explain detail...
my testpage is name box.aspx
my sql datasource is take from database is name orderdetail like this:
no order cost
1 10000
2 5000
this is box.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="box.aspx.vb" Inherits="box" %>
<!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 language="javacsript" type="text/javascript">
function DisplayConfirmation()
{
if(confirm('Are u sure'))
{
document.getElementById('<%=HiddenField1.ClientID%>').value = "true"
}
else
{
document.getElementById("<%=HiddenField1.ClientID%>").value = 'false'
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Button" /><br />
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:GAMESConnectionString %>"
SelectCommand="SELECT [no_order], [cost] FROM [orderdetail] WHERE ([no_order] = @no_order)">
<SelectParameters>
<asp:Parameter Name="no_order" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource4">
<ItemTemplate>
no_order:
<asp:Label ID="no_orderLabel" runat="server" Text='<%# Bind("no_order") %>'></asp:Label>
<br />
cost:
<asp:Label ID="costLabel" runat="server" Text='<%# Bind("cost") %>' ></asp:Label>
pay :<asp:TextBox ID="pay" runat="server"></asp:TextBox><br />
<asp:Button ID="button1" runat="server" Text="click me" CommandName="clicke" OnClick="button1_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>
</ItemTemplate>
</asp:FormView>
</form>
</body>
</html>
this is my box.aspx.vb
Partial Class box
Inherits System.Web.UI.Page
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.SqlDataSource4.SelectParameters(0).DefaultValue = 1
End Sub
Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
If Page.IsPostBack = True Then
Dim cost As Label = Me.FormView1.FindControl("costlabel")
Dim label As Label = Me.FormView1.FindControl("label1")
Dim pay As TextBox = Me.FormView1.FindControl("pay")
If Convert.ToInt32(cost.Text) > Convert.ToInt32(pay.Text) Then
Dim but As Button = FormView1.FindControl("button1")
but.Attributes.Add("onclick", "DisplayConfirmation()")
End If
End If
End Sub
Protected Sub FormView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles FormView1.ItemCommand
End Sub
Protected Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim cost As Label = Me.FormView1.FindControl("costlabel")
Dim label As Label = Me.FormView1.FindControl("label1")
Dim pay As TextBox = Me.FormView1.FindControl("pay")
Session("cost") = cost
If Convert.ToInt32(cost.Text) < Convert.ToInt32(pay.Text) Then
label.Text = "your money is overloaded"
Else
If (HiddenField1.Value.ToLower() = "true") Then
Response.Write("your money is little")
Else
Response.Write("your money is small")
End If
End If
End Sub
End Class
the code in top is error textbox(pay)...
i want:
if i run page,it will display button. after click the button, it display formview. in formview is containning :
no order label(id:no_orderlabel)
cost label(id:costlabel)
pay textbox(id:pay)
click me(buton)
that pay(textbox) is manually i add it...
because in button2_click event use the code Me.SqlDataSource4.SelectParameters(0).DefaultValue = 1
so the first i click button, it will display data in formview with condition no order=1, like that:
no order 1
cost 10000
pay textbox(id:pay)
click me(buton)
so, i can input value to textbox. if i input 20000, it will display label "your money is overloaded"
if i input 200, it will display msgbox that have yes/no statement..
as long as i try and try again about code in top and change it, it can work but have problem like:
-can display msgbox, but in the second click.. the msgbox is late to display..
-can display msgbox at first click, but if i input 20000, it display msgbox and label. it should only display label..
so how to solve that problem?
i have try 30 hours for this...
the code in the top almost work,it's only error "format string....." at line textbox(pay). because i am using page.ispostback=true, the data in databound is firing the first before button1_click event fired. so it's to late to input value to textbox(pay), so value in pay is empty, and it display error"format string...." i must use page.ispostback=true, so the msgbox is not late to show...
how should i do?
is there need change javascript or other event?
pls... thx...
Charles Asbo...
Contributor
5512 Points
1186 Posts
Re: javascript and label is firing in the formview with condition..
Jan 24, 2008 01:12 PM|LINK
Can you download the AJAX toolkit? There's a toolkit item that extends a textbox with a confirm dialog already built in.
It took me about 2 hours to get AJAX installed and running and then it's a piece of cake. Looks good on your resume too.
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
hardy
Member
350 Points
477 Posts
Re: javascript and label is firing in the formview with condition..
Jan 24, 2008 01:34 PM|LINK
my connection is not fast.
how much capasity of ajax download?
MB?
thx..
Charles Asbo...
Contributor
5512 Points
1186 Posts
Re: javascript and label is firing in the formview with condition..
Jan 24, 2008 01:50 PM|LINK
3.4MB
http://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=8513
Charlie Asbornsen
Dont forget to click "Mark as Answer" on the post that helped you.
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.