我添加了一个
jquery模式弹出窗口来保存特定设备的上传文件.弹出模式,取消按钮工作,但我无法弄清楚如何让保存按钮激活onclick事件…
这就是我所做的:
$(function () { $("#dialogCustUploads").dialog("destroy"); $("#dialogCustUploads").dialog({ title: "Upload Files",autoOpen: false,modal: true,resizable: false,width: 'auto',buttons: { Save: function () { $(document.getElementById('<%=btnSave.ClientID %>')).click(); },Cancel: function () { $(this).dialog("close"); } } }); }); function showCustUploads() { $(function () { $("#dialogCustUploads").dialog("open"); }); $(".dialogCustUploads").parent().appendTo($("form:first")); } <div id="dialogCustUploads" style="display: none"> <table style="width:100%;"> <tr> <td class="auto-style1"> <asp:Label ID="Label16" runat="server" Text="Client"></asp:Label> </td> <td> <asp:Label ID="lblClientUploadName" runat="server"></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="Label19" runat="server" Text="Certificate no" ></asp:Label> </td> <td> <asp:TextBox ID="txtCertificateNo" runat="server" Width="410px"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label14" runat="server" Text="Upload Option"></asp:Label> </td> <td> <asp:DropDownList ID="lstUploadOption" runat="server" AppendDataBoundItems="True" Width="410px"></asp:DropDownList> </td> </tr> <tr> <td class="auto-style1"> <asp:Label ID="Label18" runat="server" Text="File"></asp:Label> </td> <td> <asp:FileUpload ID="fuPath" runat="server" Width="408px" /> <br /> <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label> </td> </tr> <tr> <td class="auto-style1"></td> <td> <asp:Button ID="btnSave" style="display: none;" runat="server" Text="Save" OnClientClick="btnSave_Click" BackColor="White" /> </td> </tr> </table> </div>
我不确定我错过了什么或做错了…这是我第一次使用javascript …任何帮助将不胜感激!!!!保存按钮什么都不做……
编辑
谢谢大家的帮助!
我更新了我的按钮以删除内联样式:
<asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="btnSave_Click" ClientIDMode="Static" />
我已经尝试使用您提供给我的以下内容:
1. $("#<%=btnSave.ClientID%>").click(); 2. document.getElementById('<%=btnSave.ClientID %>').click(); 3. <asp:Button ID="btnSave" style="display: none;" runat="server" Text="Save" OnClientClick="btnSave_Click" ClientIDMode="Static" BackColor="White" /> document.getElementById('btnSave').click(); 4. $('<%=btnSave.ClientID %>').trigger("click");
Microsoft JScript runtime error: 'btnSave_Click' is undefined
当表单中断按钮时,内容如下:
<input type="submit" name="ctl00$MainContent$btnSave" value="Save" onclick="btnSave_Click;" id="btnSave" />
我正在做什么还有什么不对吗?
编辑
这是我的源代码:
<script type="text/javascript"> $(function () { $("#dialog").dialog("destroy"); $("#dialog").dialog({ title: "Message",buttons: { Ok: function () { $(this).dialog("close"); } } }); }); function showMessage() { $(function () { $("#dialog").dialog("open"); }); return false; } $(function () { $("#dialogCustUploads").dialog("destroy"); $("#dialogCustUploads").dialog({ title: "Upload Files",buttons: { Save: function () { document.getElementById('<%=btnSave.ClientID %>').click(); },Cancel: function () { $(this).dialog("close"); } } }); }); function showCustUploads() { $(function () { $("#dialogCustUploads").dialog("open"); }); $(".dialogCustUploads").parent().appendTo($("form:first")); } </script>
我的div所在的按钮点击事件:
<div id="dialogCustUploads" style="display: none"> <table style="width:100%;"> <tr> <td class="auto-style1"> <asp:Label ID="Label16" runat="server" Text="Client"></asp:Label> </td> <td> <asp:Label ID="lblClientUploadName" runat="server"></asp:Label> </td> </tr> <tr> <td> <asp:Label ID="Label19" runat="server" Text="Certificate no" ></asp:Label> </td> <td> <asp:TextBox ID="txtCertificateNo" runat="server" Width="410px"></asp:TextBox> </td> </tr> <tr> <td> <asp:Label ID="Label14" runat="server" Text="Upload Option"></asp:Label> </td> <td> <asp:DropDownList ID="lstUploadOption" runat="server" AppendDataBoundItems="True" Width="410px"></asp:DropDownList> </td> </tr> <tr> <td class="auto-style1"> <asp:Label ID="Label18" runat="server" Text="File"></asp:Label> </td> <td> <asp:FileUpload ID="fuPath" runat="server" Width="408px" /> <br /> <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label> </td> </tr> <tr> <td class="auto-style1"></td> <td> <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" /> </td> </tr> </table> </div>
我通过gridview中的单击调用模态弹出窗口:
<asp:GridView ID="gvDeviceCalibration" runat="server" CellPadding="10" Width="90%" AutoGenerateColumns="False" BorderWidth="1px"> <HeaderStyle BackColor="#3A4F63" BorderWidth="1px" Font-Size="7pt" Wrap="False" ForeColor="White" /> <RowStyle BackColor="White" Wrap="True" /> <AlternatingRowStyle BackColor="#FFCC99" Wrap="True" /> <Columns> <asp:BoundField datafield="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" ></asp:BoundField> <asp:BoundField datafield="InstrumentType" HeaderText="Instrument Type" ReadOnly="True" SortExpression="InstrumentType"> <HeaderStyle Wrap="True" /></asp:BoundField> <asp:BoundField datafield="Make" HeaderText="Make" ReadOnly="True" SortExpression="Make"> <HeaderStyle Wrap="True" /> </asp:BoundField> <asp:BoundField datafield="Location" HeaderText="Location" ReadOnly="True" SortExpression="Location"></asp:BoundField> <asp:BoundField datafield="SubLocation" HeaderText="Sub Location" ReadOnly="True" SortExpression="Sub Location"> <HeaderStyle Wrap="True" /></asp:BoundField> <asp:BoundField datafield="CalibrationIntervals" HeaderText="Calibration Intervals" ReadOnly="True" SortExpression="CalibrationIntervals"> <HeaderStyle Wrap="True" /></asp:BoundField> <asp:BoundField datafield="SerialNo" HeaderText="Serial No" ReadOnly="True" SortExpression="SerialNo"> <HeaderStyle Wrap="True" /></asp:BoundField> <asp:BoundField datafield="WorkingRange" HeaderText="Working Range" ReadOnly="True" SortExpression="WorkingRange"> <HeaderStyle Wrap="True" /></asp:BoundField> <asp:BoundField datafield="Classification" HeaderText="Classification" ReadOnly="True" SortExpression="Classification"></asp:BoundField> <asp:BoundField datafield="CalibrationDate" HeaderText="Calibration Date" DataFormatString="{0:yyyy/MM/dd}" ReadOnly="True" SortExpression="CalibrationDate"> <HeaderStyle Wrap="True" /> </asp:BoundField> <asp:BoundField datafield="CalibrationHouse" HeaderText="Calibration House" ReadOnly="True" SortExpression="CalibrationHouse"><HeaderStyle Wrap="True" /></asp:BoundField> <asp:BoundField datafield="Owner1s" HeaderText="Owner 1" ReadOnly="True" SortExpression="Owner1s"></asp:BoundField> <asp:BoundField datafield="Owners2" HeaderText="Owner 2" ReadOnly="True" SortExpression="Owners2"></asp:BoundField> <asp:BoundField datafield="CreatedBy" HeaderText="Created By" ReadOnly="True" SortExpression="CreatedBy"></asp:BoundField> <asp:TemplateField HeaderText="Select"> <ItemTemplate> <asp:ImageButton ID="UpdateStatus" runat="server" Height="22" BorderStyle="None" BackColor="Transparent" ImageUrl="~/Images/Sign-Select-icon.png" OnClick="SelectCalDevice_Click" Width="22" /><%-- --%> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Upload"> <ItemTemplate> <asp:ImageButton ID="CustUploadFiles" runat="server" Height="22" BorderStyle="None" BackColor="Transparent" ImageUrl="~/Images/UploadFilesTrans.png" OnClick="SelectCustFiles_Click" Width="22" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="View "> <ItemTemplate> <asp:ImageButton ID="CustViewFiles" runat="server" Height="25" BorderStyle="None" BackColor="Transparent" ImageUrl="~/Images/msgicon.png" ForeColor="Transparent" Width="25" OnClick="ViewCustFiles_Click" /> </ItemTemplate> </asp:TemplateField> </Columns> <EmptyDataTemplate> <HeaderTemplate>There are no leads listed.</HeaderTemplate> </EmptyDataTemplate> </asp:GridView>
这是我显示弹出窗口的SelectCustFiles_Click:
protected void SelectCustFiles_Click(object sender,EventArgs e) { ImageButton lb = sender as ImageButton; GridViewRow row = (GridViewRow)lb.NamingContainer; txtRowID.Text = row.Cells[0].Text; lblClientUploadName.Text = row.Cells[1].Text; PopulateUploadOptions(); //modalCustUploads.Show(); this.Page.ClientScript.RegisterStartupScript(this.GetType(),"popUpMessage","showCustUploads();",true); }
这是我试图从脚本调用的click事件:
protected void btnSave_Click(object sender,EventArgs e) { // Before attempting to save the file,verify // that the FileUpload control contains a file. if (fuPath.HasFile) { // Get the size in bytes of the file to upload. int fileSize = fuPath.PostedFile.ContentLength; // Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded. if (fileSize < 45497717) { // Call a helper method routine to save the file. //SaveFile(fuPath.PostedFile); SaveFile(); fuPath.dispose(); lbljQMessage.Text = "Update successful"; this.Page.ClientScript.RegisterStartupScript(this.GetType(),true); //modalCustUploads.Show(); } else lblMessage.Text = "You did not specify a file to upload."; } }
我收到错误’btnSave’未定义…
这是我正在使用的脚本:
<script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script> <script src="../Scripts/jquery-ui-1.8.17.custom.min.js" type="text/javascript"></script>
解决了
function showCustUploads() { $(function () { $("#dialogCustUploads").dialog("open"); }); $(".dialogCustUploads").parent().appendTo($("form:first")); }
它应该是:
function showCustUploads() { $(function () { $("#dialogCustUploads").dialog("open"); }); }
而不是这个:
$(function () { $("#dialogCustUploads").dialog("destroy"); $("#dialogCustUploads").dialog({ title: "Upload Files",buttons: { Save: function () { // __doPostBack("<%=btnSave.UniqueID %>",""); $($get("<%=btnSave.UniqueID %>")).click(); },Cancel: function () { $(this).dialog("close"); } } }); });
它应该是:
$(function () { $("#dialogCustUploads").dialog("destroy"); var dlgUploads = $("#dialogCustUploads").dialog({ title: "Upload Files",Cancel: function () { $(this).dialog("close"); } } }); dlgUploads.parent().appendTo(jQuery("form:first")); });
谢谢大家的帮助!欣赏它!
解决方法
document.getElementById('<%=btnSave.ClientID %>').click(); Or $('#<%=btnSave.ClientID %>').click();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。