Javascript获取控件insGridView [英] Javascript getting controls insde a gridview

查看:67
本文介绍了Javascript获取控件insGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.这里有一个大问题.如何使用javascript:在gridview中获取控件:
我正在使用此代码,但我不知道它是否正确.
它在我的服务器端

Hello guys. got a huge problem here. How can I get the controls inside gridview using javascript:
I am using this code but I dont know if it is right or not.
It is on my server side

Protected Sub grdCategory_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdCategory.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
 Dim txttry As TextBox = DirectCast(e.Row.FindControl("txtCourseCategory"), TextBox)
            Dim labeltry As Label = DirectCast(e.Row.FindControl("lbllastname"), Label)
            labeltry.Attributes.Add("onclick", "javascript:return validate('" + txttry.ClientID + "','" + labeltry.ClientID + "')")
end if


现在在我的客户端


now on my client side

function validate(perobj, stockobj) {
          alert(perobj)
      }


它说我很警惕
ctl00_ContentPlaceHolder1_gridCategory_ctl02_txtCourseCategory
当我将其更改为


it says on my alert
ctl00_ContentPlaceHolder1_gridCategory_ctl02_txtCourseCategory
and when I change it to

function validate(perobj, stockobj) {
           document.getElementById('<%=perobj.ClientID%>').style.display = 'none';
       }


我收到一条错误消息说未声明perobj

我想要的就是在gridview内的javascript上获得txtCourseCategory和lbllastname控件.

感谢和抱歉,我的英语


Im getting an error saying perobj is not declared

All I want Is to get the control txtCourseCategory and lbllastname on javascript inside my gridview

Thanks and sorry for my english

推荐答案

当然还没有定义.

文本"perobj.ClientID"出现在服务器端,这毫无意义.该代码首先在服务器端生成. <% ... %>中放置的是服务器端的代码.该代码在服务器端进行评估,其文本结果与HTML + JavaScript的文本(插入其中)组合在一起.从服务器端代码的角度来看,它周围的所有内容都只是文本. function validate(perobj, stockobj)的声明是JavaScript代码,仅在将HTTP响应发送到客户端后才在客户端进行解释.该客户端代码根本不存在,就像服务器端代码一样.

整个想法是错误的,因此我认为此代码完全无法修复.

您显然不知道在服务器端和客户端会发生什么,所以这就是您遇到各种问题的原因.从这个以及您以前的一些问题中,我看不到您如何有意识地开发ASP.NET和任何其他高级类型的应用程序.您宁愿需要一本有关C#和.NET的好书,并从头到尾全部阅读,仅使用控制台应用程序进行简单的练习.

—SA
Of course it is not defined.

The text "perobj.ClientID" appears on server side where it makes no sense. The code is generated on server side first. What is placed in <% ... %> is the code on the server side. This code is evaluated on the server side and the text result of it is combined with the text of HTML+JavaScript (inserted in it). From the standpoint of server-side code, everything around it is just the text. The declaration of function validate(perobj, stockobj) is the JavaScript code which will be interpreted only after the HTTP response is sent to the client, and only on client side. This client-side code simply does not exist as such for the server-side code.

The whole idea is wrong, so I think this code is totally beyond repair.

You apparently have no idea what happens on server side and client side, and that''s why you have all kinds of problems. From this and some of your previous questions I cannot see how can you knowingly develop ASP.NET and any other advanced types of applications. You rather need a good book on C# and .NET and read it all from beginning to the end, do simple exercises using just the console applications.

—SA



如果您的警报显示
ctl00_ContentPlaceHolder1_gridCategory_ctl02_txtCourseCategory
则不要使用服务器标签<%= ...%>只需使用
perobj本身就像
Hi,
if your alert shows
ctl00_ContentPlaceHolder1_gridCategory_ctl02_txtCourseCategory
then do not use the server tag <%=... %> just use
perobj itself like
function validate(perobj, stockobj) {
           document.getElementById(perobj).style.display = 'none';
       }



希望这会成功.



hope this will work.


这篇关于Javascript获取控件insGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆