本文介绍了如何使用asp.net页面中的Jquery更新usercontrol的updatepanel中的文本框控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 以下是上传或更改文件时更改事件的Jquery代码。 var document1FileUpload = $( ' #Document1FileUpload'); var fileNameTextBox1 = $(' #fileNameTextBox1 ); document1FileUpload.die(); document1FileUpload.live(' change',function(){ console。 log( 1 Doc up); if ( this .files!= undefined || this .files!= null ){ fileNameTextBox1.val( this .files [ 0 ]。name); console.log( if block); } else { var filePath = this 。 value .split( \\); fil eNameTextBox1.attr(' value',filePath [filePath.length - 1 ]); console.log( else block); } }); 以下是设计师代码: < asp:UpdatePanel ID = UpdatePanel1 runat = server > < 触发器 > < asp:PostBackTrigger ControlID = BulkUploadButton / > < /触发器 > < ContentTemplate > < table style = width:100%; > < tr > < td style = width: 5em; > < web:Label AssociatedControlID = Document1FileUpload 字体大小 = X-Small 文字 = File.1 runat = server style = padding-left:0px; / > < br / > < asp:FileUpload runat = server ID = Document1FileUpload / > < / td > < td 样式 = width:5em; > < web:Label AssociatedControlID = DocumentTypeDropdownList1 字体大小 = X-Small 文字 = ); var fileNameTextBox1 = (' #fileNameTextBox1' ); document1FileUpload.die(); document1FileUpload.live(' change',function(){ console。 log( 1 Doc up); if ( this .files!= undefined || this .files!= null ){ fileNameTextBox1.val( this .files [ 0 ]。name); console.log( if block); } else { var filePath = this 。 value .split( \\); fil eNameTextBox1.attr(' value',filePath [filePath.length - 1 ]); console.log( else block); } }); 以下是设计师代码: < asp:UpdatePanel ID = UpdatePanel1 runat = server > < 触发器 > < asp:PostBackTrigger ControlID = BulkUploadButton / > < /触发器 > < ContentTemplate > < table style = width:100%; > < tr > < td style = width: 5em; > < web:Label AssociatedControlID = Document1FileUpload 字体大小 = X-Small 文字 = File.1 runat = server style = padding-left:0px; / > < br / > < asp:FileUpload runat = server ID = Document1FileUpload / > < / td > < td 样式 = width:5em; > < web:Label AssociatedControlID = DocumentTypeDropdownList1 字体大小 = X-Small 文字 = Type.1 runat = server 样式 = padding-left: 0px; / > < br / > < web:DropDownList runat = server ID = DocumentTypeDropdownList1 宽度 = 100px 高度 = 20px > < / web:DropDownList > < / td > < td style = width:250px; > < web:Label AssociatedControlID = FileNameTextBox1 字体大小 = X -Small 文字 = 文件名1 runat = server style = padding-left:0px; / > < br / > < web:TextBox ID = FileNameTextBox1 runat = server MaxLength = 150 TextMode = SingleLine 宽度 = 250px 高度 = 20px OrgValue = / > < / td > < td style = width: 300px; > < web:Label AssociatedControlID = Description1TextBox 字体大小 = X-Small 文字 = Description.1 runat = server style = padding-left:0px; / > < br / > < web:TextBox ID = Description1TextBox runat = server MaxLength = 250 TextMode = SingleLine 宽度 = 100% 高度 = 20px / > < / td > < / tr > < / table > < / ContentTemplate > < / asp:UpdatePanel > The problem is when ever the file upload change event occurs the Description text does not update with respected file name. I also mention the file name as well as written to change the value according to the jquery coding standard. Please any help on this topic is much appreciated. Thanks fellow fantastic coder.Following is the Jquery code for the change event whenever the file uploaded or changed. var document1FileUpload = $('#Document1FileUpload');var fileNameTextBox1= $('#fileNameTextBox1');document1FileUpload.die(); document1FileUpload.live('change', function () { console.log("1 Doc up"); if (this.files != undefined || this.files != null) { fileNameTextBox1.val(this.files[0].name); console.log("If block"); } else { var filePath = this.value.split("\\"); fileNameTextBox1.attr('value', filePath[filePath.length - 1]); console.log("else block"); } });below is the designer code:<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:PostBackTrigger ControlID="BulkUploadButton" /> </Triggers> <ContentTemplate> <table style="width:100%;"> <tr> <td style="width:5em;"> <web:Label AssociatedControlID="Document1FileUpload" Font-Size="X-Small" Text="File.1" runat="server" style="padding-left:0px;"/> <br /> <asp:FileUpload runat="server" ID="Document1FileUpload"/> </td> <td style="width:5em;"> <web:Label AssociatedControlID="DocumentTypeDropdownList1" Font-Size="X-Small" Text="Type.1" runat="server" style="padding-left:0px;"/> <br /> <web:DropDownList runat="server" ID="DocumentTypeDropdownList1" Width="100px" Height="20px"></web:DropDownList> </td> <td style="width:250px;"> <web:Label AssociatedControlID="FileNameTextBox1" Font-Size="X-Small" Text="File Name.1" runat="server" style="padding-left:0px;"/><br /> <web:TextBox ID="FileNameTextBox1" runat="server" MaxLength="150" TextMode="SingleLine" Width="250px" Height="20px" OrgValue="" /> </td> <td style="width:300px;" ><web:Label AssociatedControlID="Description1TextBox" Font-Size="X-Small" Text="Description.1" runat="server" style="padding-left:0px;" /><br /> <web:TextBox ID="Description1TextBox" runat="server" MaxLength="250" TextMode="SingleLine" Width="100%" Height="20px" /> </td> </tr></table></ContentTemplate></asp:UpdatePanel>The problem is when ever the file upload change event occurs the Description text does not update with respected file name.I also mention the file name as well as written to change the value according to the jquery coding standard.Please any help on this topic is much appreciated. Thanks fellow fantastic coder. 解决方案 ('#Document1FileUpload');var fileNameTextBox1=('#fileNameTextBox1');document1FileUpload.die(); document1FileUpload.live('change', function () { console.log("1 Doc up"); if (this.files != undefined || this.files != null) { fileNameTextBox1.val(this.files[0].name); console.log("If block"); } else { var filePath = this.value.split("\\"); fileNameTextBox1.attr('value', filePath[filePath.length - 1]); console.log("else block"); } });below is the designer code:<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:PostBackTrigger ControlID="BulkUploadButton" /> </Triggers> <ContentTemplate> <table style="width:100%;"> <tr> <td style="width:5em;"> <web:Label AssociatedControlID="Document1FileUpload" Font-Size="X-Small" Text="File.1" runat="server" style="padding-left:0px;"/> <br /> <asp:FileUpload runat="server" ID="Document1FileUpload"/> </td> <td style="width:5em;"> <web:Label AssociatedControlID="DocumentTypeDropdownList1" Font-Size="X-Small" Text="Type.1" runat="server" style="padding-left:0px;"/> <br /> <web:DropDownList runat="server" ID="DocumentTypeDropdownList1" Width="100px" Height="20px"></web:DropDownList> </td> <td style="width:250px;"> <web:Label AssociatedControlID="FileNameTextBox1" Font-Size="X-Small" Text="File Name.1" runat="server" style="padding-left:0px;"/><br /> <web:TextBox ID="FileNameTextBox1" runat="server" MaxLength="150" TextMode="SingleLine" Width="250px" Height="20px" OrgValue="" /> </td> <td style="width:300px;" ><web:Label AssociatedControlID="Description1TextBox" Font-Size="X-Small" Text="Description.1" runat="server" style="padding-left:0px;" /><br /> <web:TextBox ID="Description1TextBox" runat="server" MaxLength="250" TextMode="SingleLine" Width="100%" Height="20px" /> </td> </tr></table></ContentTemplate></asp:UpdatePanel>The problem is when ever the file upload change event occurs the Description text does not update with respected file name.I also mention the file name as well as written to change the value according to the jquery coding standard.Please any help on this topic is much appreciated. Thanks fellow fantastic coder. 这篇关于如何使用asp.net页面中的Jquery更新usercontrol的updatepanel中的文本框控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 21:53