我的asp.net程序中,有一个文本框(通过日历控件选取或输入日期)和一个按钮,每当文本框的文本改变时,按钮的enabled属性就改为false,但怎么试都不能成功。
还有在按钮的click事件中,想在事件执行完后,设定该按钮的enabled属性改为false,也不能成功!,请各位老大赐教,谢谢!
还有在按钮的click事件中,想在事件执行完后,设定该按钮的enabled属性改为false,也不能成功!,请各位老大赐教,谢谢!
<form id="form1" runat="server">
<div>
<asp:TextBox AutoPostBack="true" ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
</form>
</body>要设置你的AutoPostBack="true" 这个加上去 如果不加就得按回车
后台测试代码
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
this.TextBox1.Enabled = false;
this.Button1.Visible = false;
} protected void Button1_Click(object sender, EventArgs e)
{
this.TextBox1.ReadOnly = false ;
}
起始日期:<asp:TextBox class="input_text" id="tj_qsrq" runat="server" width="65px"
onclick="var tj_jzrq=$dp.$('tj_jzrq');WdatePicker({onpicked:function(){tj_jzrq.focus();},dateFmt:'yyyyMMdd',maxDate:'#F{$dp.$D(\'tj_jzrq\')}'})"
style="height: 16px"></asp:TextBox> <asp:button class="input_button" id="toexcel" onclick="Excel_Click" runat="server" text="生成Excel" ontextchange="tj_qsrq_ontextchange"></asp:button>
<asp:button class="input_button" id="cxbtn" onclick="cxbtn_Click" runat="server" text="查询" ontextchange="tj_qsrq_ontextchange"></asp:button>
Imports System.Data
Imports System.Data.OracleClient
Imports excel = Microsoft.Office.Interop.Excel
Imports System.Runtime.InteropServices.Marshal
Imports System.Web
Imports System.IOPartial Class rpt_18reportcx
Inherits System.Web.UI.Page
Dim Cnn As OracleConnection
Dim cmd As OracleCommand
Dim ad1, ad2 As New OracleClient.OracleDataAdapter()
Dim dt, dt1 As New DataTable
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs) Handles Me.Load
If Not IsPostBack Then
tj_qsrq.Text = Today().ToString("yyyyMMdd")
toexcel.enabled=False
End If
End Sub
Sub Excel_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim item_t, str1, str2 As String
Dim oExcel As New excel.Application()
Dim oBooks As excel.Workbooks = oExcel.Workbooks
Dim oBook As excel.Workbook
Dim oSheets As excel.Sheets, oSheet As excel.Worksheet
Dim oCells As excel.Range
Dim sFile, sFile1 As String
Dim dr As DataRow, ary() As Object
Dim iRow As Integer, iCol As Integer
Dim item_num As Integer
Dim dataR As OracleDataReader
If Drop_unit.SelectedValue = "JHA" Then
Page.RegisterStartupScript("", GetAlertInfo("不支持打印!"))
Return
End If toexcel.Enabled=False str1 = "select sta_date,F001"
For i = 2 To 100
item_t = "F" + i.ToString("000")
str1 = str1 + "," + item_t
Next
str1 = str1 + " from tj_report where rpt_code='" + Drop_rpt.SelectedValue + "' and unit_code='" + Drop_unit.SelectedValue + "' and sta_date<='" + tj_jzrq.Text + "' and sta_date>='" + tj_qsrq.Text + "' order by sta_date"
Try
Cnn = New OracleConnection(ConfigurationSettings.AppSettings("connection1"))
Cnn.Open()
item_num = 0
str2 = "select count(*) as nums from tj_report_item where rpt_code='" + Drop_rpt.SelectedValue + "'"
cmd = New OracleCommand(str2, Cnn)
dataR = Nothing
dataR = cmd.ExecuteReader()
If dataR.Read() Then
item_num = CInt(dataR("nums").ToString())
Else
item_num = 0
End If
dataR.Close()
oExcel.Visible = False
oExcel.UserControl = True
sFile1 = Trim(Drop_unit.SelectedValue) + "_" + Trim(Drop_rpt.SelectedValue) + ".xls"
sFile = Server.MapPath(Request.ApplicationPath) & "\18report\rpt\" + sFile1
If System.IO.File.Exists(sFile) Then
System.IO.File.Delete(sFile)
End If
oBooks.Open(Server.MapPath(Request.ApplicationPath) & "\18report\mb\" + Trim(Drop_rpt.SelectedValue) + ".xlt")
oBook = oBooks.Item(1)
oSheets = oBook.Worksheets
oSheet = CType(oSheets.Item(1), excel.Worksheet)
oSheet.Name = "First Sheet"
oCells = oSheet.Cells
ad1 = New OracleDataAdapter(str1, Cnn)
ad1.Fill(dt1)
For iRow = 0 To dt1.Rows.Count - 1
dr = dt1.Rows.Item(iRow)
ary = dr.ItemArray
For iCol = 0 To item_num
If ary(iCol).ToString <> "0" Then
oCells(iRow + 8, iCol + 1) = ary(iCol).ToString
End If
Next
Next
'黑色连续边框
oSheet.Range(oCells(8, 1), oCells(dt1.Rows.Count + 7, item_num + 1)).Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black)
oSheet.SaveAs(sFile)
Finally
oBook.Close()
oExcel.Quit()
ReleaseComObject(oCells) : ReleaseComObject(oSheet)
ReleaseComObject(oSheets) : ReleaseComObject(oBook)
ReleaseComObject(oBooks) : ReleaseComObject(oExcel)
oExcel = Nothing : oBooks = Nothing : oBook = Nothing
oSheets = Nothing : oSheet = Nothing : oCells = Nothing
System.GC.Collect()
Cnn.Close()
Context.Response.ContentType = "application/x-excel"
Context.Response.AddHeader("content-disposition", "attachment;filename=" + Server.UrlEncode(sFile1))
Context.Response.WriteFile(sFile)
Context.Response.End()
End Try
End Sub
Sub tj_qsrq__textchange(ByVal sender As Object, ByVal e As EventArgs)
toexcel.enabled=False
End Sub
Sub cxbtn__textchange(ByVal sender As Object, ByVal e As EventArgs)
toexcel.enabled=true
End Sub
End Class
那如何再次启用呢?
function checkText(){
var vT=document.getElementById("txtNR");
if(vT.value.length>50){
alert("输入的内容不得超过50个字!");
return false;
}
else {
document.getElementById("btnSub").disabled = true;
__doPostBack("btnSub2", "");
return true;
}
}
<head runat="server">
<title></title> <script src="jQuery/jquery-1.4.1.min.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" onpropertychange="txtChange()"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
<script language="javascript" type="text/javascript">
function txtChange() {
$("#Button1").attr("disabled",true);
}
</script>
</html>