javascript for show并在点击linkbutton时隐藏usercontrol [英] javascript for show and hide usercontrol on click of linkbutton
本文介绍了javascript for show并在点击linkbutton时隐藏usercontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是aspx页面
< ;%@ Page 语言 = C# AutoEventWireup = true CodeFile = hyperlink.aspx.cs 继承 = 超链接 %>
<%@ 注册 Src = 〜/ hyperlinkusercontrol.ascx 标记名 = abc tagprefix = uc1 %>
< !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 = 服务器 >
< title > < / title >
< / head >
< body >
< 表格 id = form1 runat = 服务器 >
< div >
< uc1:abc id = abc runat = 服务器 可见 = true / >
< / div >
< p >
< asp:LinkButton ID = LinkButton1 runat = 服务器 > LinkButton
< / p >
< p >
< / p >
< p >
< / p >
< p >
< / p > ;
< / form >
< / body >
< / html >
这是ascx页面
<%@ 控制 语言 = C# AutoEventWireup = true CodeFile = hyperlinkusercontrol.ascx.cs 继承 = hyperlinkusercontrol %>
< style type = text / css >
。 style1
{
宽度 : 100%;
}
。 style2
{
width : 63px;
}
< / 风格 >
< 表 class = style1 >
< tr >
< td class = style2 >
用户< / td >
< td < span class =code-keyword>>
< asp:TextBox ID = TextBox1 runat = 服务器 > < / asp:TextBox >
< / td >
< / tr >
< tr >
< td class = style2 >
pwd < / td >
< td >
&l t; asp:TextBox ID = TextBox2 runat = server > < / asp:TextBox >
< / td >
< / tr < span class =code-keyword>>
< tr >
< td class = style2 >
< ; asp:标签 ID = Label1 runat = server 文本 = 标签 > < / asp:标签 >
< / td >
< td >
< asp:按钮 ID = Button1 runat = server onclick = Button1_Click 文本 = 按钮 / >
< / td >
< / tr >
< / table >
这是ascx.cs
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.Security;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data;
使用 System.Web.UI.HtmlControls;
使用 System.Web.UI.WebControls.WebParts;
使用 System.Configuration;
public partial class hyperlinkusercontrol:System.Web.UI.UserControl
{
protected void Page_Load( object sender,EventArgs e)
{
}
protected void Button1_Click( object sender,EventArgs e)
{
if (TextBox1.Text == mann && TextBox2.Text == rai)
{
Label1.Text = helloo welcm;
}
else
{
Label1.Text = 输入错误;
}
Label1.Enabled = true ;在aspx页面上
}
}
解决方案
,将用户控件放在div中 -
< div class = controlParent >
< uc1:abc id = someId runat = server xmlns:uc1 = #unknown / >
< / div >
在你的链接按钮上添加 CssClass -
< pre lang =HTML> < asp:linkbutton id = LinkButton1 runat = server text = 显示/隐藏 cssclass = btnHide xmlns:asp = #unknown / >
在你的aspx页面的 head 部分,写一下javascript就像 -
< ;! - 在这里添加jquery.min.js文件路径, - >
< script type = text / javascript>
( document )。ready(funcyion(){
( 。btnHide)。click( function (){
This is aspx page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="hyperlink.aspx.cs" Inherits="hyperlink" %>
<%@ Register Src="~/hyperlinkusercontrol.ascx" tagname="abc" tagprefix="uc1"%>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:abc id="abc" runat="server" visible=true/>
</div>
<p>
<asp:LinkButton ID="LinkButton1" runat="server">LinkButton
</p>
<p>
</p>
<p>
</p>
<p>
</p>
</form>
</body>
</html>
this is ascx page
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="hyperlinkusercontrol.ascx.cs" Inherits="hyperlinkusercontrol" %>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 63px;
}
</style>
<table class="style1">
<tr>
<td class="style2">
User</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
pwd</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
<td>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</td>
</tr>
</table>
this is ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Configuration;
public partial class hyperlinkusercontrol : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if(TextBox1.Text=="mann"&& TextBox2.Text=="rai")
{
Label1.Text = "helloo welcm";
}
else
{
Label1.Text = "error in input";
}
Label1.Enabled = true;
}
}
解决方案
on aspx page, put you user control inside a div -
<div class="controlParent"> <uc1:abc id="someId" runat="server" xmlns:uc1="#unknown" /> </div>
On your linkbutton add CssClass -
<asp:linkbutton id="LinkButton1" runat="server" text="Show/Hide" cssclass="btnHide" xmlns:asp="#unknown" />
In head section of your aspx page, write javascript like -
<!-- Add you jquery.min.js file path here, --> <script type="text/javascript">
(document).ready(funcyion(){
(".btnHide").click(function(){
这篇关于javascript for show并在点击linkbutton时隐藏usercontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文