开发者

Find Control using javascript inside an ASP:Login control

开发者 https://www.devze.com 2023-04-09 21:37 出处:网络
I have an ASP Login control box on the page which is customized. Insi开发者_JAVA百科de the Login control we have Username and password textboxes.

I have an ASP Login control box on the page which is customized.

Insi开发者_JAVA百科de the Login control we have Username and password textboxes.

I want to find username and password controls with a javascript function.

var Username= document.getElementById("<%=UserName.ClientID%>");

But this code does not compile and gives compile time error

UserName not found in this context.

and if I write the client side id :

var username = document.getElementById("login_LoginUser_UserName");

it executes properly, but I want to find the client id rather than using a hardcoded id here.


The only way which I know is:

 var Username = document.getElementById("<%= Login1.FindControl("UserName").ClientID %>");
 var Password = document.getElementById("<%= Login1.FindControl("Password").ClientID %>");

It will returns the client Id of the controls inside of Login control.

0

精彩评论

暂无评论...
验证码 换一张
取 消