Passing ASp.net Server Control Id to javascript function

benjamin200

New Member
I have an ASP.NET page that contains a JavaScript function as follows:\[code\]function PrintGridView(Title,Address,Terms,GridViewName) { if (document.getElementById != null) { var html = '<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" xml:lang="en"><HTML>\n\n'; html += '<head> <title>' + Title + '</title> <link href="http://stackoverflow.com/questions/15655567/Styles/Print.css" rel="stylesheet" type="text/css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; html += ""; html += '</head>'; html += '<body> <div id="page-wrap">'; html += '<textarea id="header">'+Title+'</textarea>'; html += '<div id="identity">'; html += '<textarea id="address">'+Address+'</textarea>'; html += '<div id="logo">'; html += '<div id="logohelp">'; html +='<input id="imageloc" type="text" size="50" value="" /><br />'; html +='(max width: 540px, max height: 100px)'; html +='</div>'; html += '<img id="image" src="http://stackoverflow.com/questions/15655567/images/smallLogo.png" alt="logo" />'; html +='</div>'; html += '</div>'; html += '<div style="clear:both"></div>'; var tablerow = GridViewName.getElementsByTagName("tr"); html += '<table align="center" id="items">'; var td = tablerow.item(0).getElementsByTagName("th"); html += '<tr>'; // Get Table Header for (var i = 1; i < td.length ; i++) { html +='<th width=auto>'+td.item(i).innerText+'</th>'; } html += '</tr>'; //Get Table Rows Data if (tablerow.length > 10) var Rowlen = 11; else var Rowlen = tablerow.length -1; for (var j = 1; j < Rowlen; j++) { html += '<tr class="item-row">'; var tRow= tablerow.item(j).getElementsByTagName("td"); for (var i = 1; i < 3; i++) { html += '<td >' + tRow.item(i).innerText + '</td>'; } html += '</tr>'; } html += '</table>'; html += '<div id="terms"> <h5>notice</h5> <textarea>'+Terms+'</textarea></div>'; html +='</div></body></html>'; } var printWin = window.open("", "PrintGridView"); printWin.document.open(); printWin.document.write(html); printWin.document.close(); //printWin.print();}\[/code\]The ASP.NET page is as follows:\[code\]<%@ Page Title="Damascus University-Institutes Management System" Language="C#" MasterPageFile="~/University.master" AutoEventWireup="true" CodeBehind="UniPunishmentRewardInfo.aspx.cs" Inherits="InstitutesManagementSystem.RewardPunishmentInfo" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %><asp:Content ID="Content1" ContentPlaceHolderID="ContainerHolder" runat="server"> <script type="text/javascript"> // PrintGridView(Title,Address,Terms,GridViewName) code is here </script> <asp:TabContainer ID="TabContainer" runat="server" Width="700px" ActiveTabIndex="0" OnDemand="true" AutoPostBack="false" TabStripPlacement="Top" CssClass="fancy fancy-green" ScrollBars="None" UseVerticalStripPlacement="false" VerticalStripWidth="120px" onactivetabchanged="TabContainer_ActiveTabChanged" ViewStateMode="Enabled"> <asp:TabPanel ID="TabPanelSendingDownType" runat="server" HeaderText="Typs" Enabled="true" ScrollBars="Auto" OnDemandMode="Once" ViewStateMode="Enabled"> <ContentTemplate> <asp:UpdatePanel ID="UpdatePanelSendingDownType" runat="server" UpdateMode="Conditional"> <ContentTemplate> <table align="center" class="tabContainerTable" > <tr class="tabContainerTableRow"> <td align="center" > <table align="center"> <tr> <td> <asp:ImageButton ID="SendingDownTypeRefreshImageButton" runat="server" ImageUrl="~/images/refresh.png" ToolTip="Refresh" onclick="SendingDownTypeRefreshImageButton_Click" /> </td> <td> <asp:ImageButton ID="SendingDownTypePrintImageButton" runat="server" ImageUrl="~/images/printer.png" ToolTip="Print" onclick="SendingDownTypePrintImageButton_Click" OnClientClick="PrintGridView('university',' address','Terms','"<%=SendingDownTypeGridView.ClientID>"')"/> </td> </tr> </table> </td> </tr> <tr class="tabContainerTableRow" > <td align="center" class="tabContainerTableCell" ><asp:Label ID="SendingDownResultsLabel" runat="server"></asp:Label></td> </tr> <tr class="tabContainerTableRow"> <td align="center" class="tabContainerTableCell" > <asp:Panel ID="PanelSendingDownType" runat="server" ScrollBars="Auto" Width="650px"> <asp:GridView ID="SendingDownTypeGridView" runat="server" DataKeyNames="SendingDownTypeID" HeaderStyle-BackColor="#61A6F8" ShowFooter="True" HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="White" AutoGenerateColumns="False" HorizontalAlign="Center" onrowcommand="SendingDownTypeGridView_RowCommand" DataSourceID="SendingDownTypeSqlDataSource" AllowPaging="True" AllowSorting="True"> <Columns> <asp:TemplateField HeaderText="???????" HeaderStyle-HorizontalAlign="center"> <EditItemTemplate> <asp:ImageButton ID="SendingDownTypeImgBtnUpdate" CommandName="Update" runat="server" ImageUrl="~/images/save.png" ToolTip="Update" Height="20px" Width="20px" /> <asp:ImageButton ID="SendingDownTypeImgBtnCancel" runat="server" CommandName="Cancel" ImageUrl="~/images/exit.png" ToolTip="Cancel" Height="20px" Width="20px" /> </EditItemTemplate> <ItemTemplate> <asp:ImageButton ID="SendingDownTypeImgBtnEdit" CommandName="Edit" runat="server" ImageUrl="~/images/edit.png" ToolTip="Edit" Height="20px" Width="20px" /> <asp:ImageButton ID="SendingDownTypeImgBtnDelete" CommandName="Delete" Text="Remove" runat="server" ImageUrl="~/images/-.png" ToolTip="Remove" Height="20px" Width="20px" /> </ItemTemplate> <FooterTemplate> <asp:ImageButton ID="SendingDownTypeImgBtnAppend" runat="server" ImageUrl="~/images/+.png" CommandName="Insert" Width="30px" Height="30px" ToolTip="Append" ValidationGroup="Tab1" /> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="??? ??? ?????" HeaderStyle-HorizontalAlign="center"> <EditItemTemplate> <asp:Label ID="EditSendingDownTypeIDLable" runat="server" CssClass="input" Text='<%#Eval("SendingDownTypeID") %>'/> </EditItemTemplate> <ItemTemplate> <asp:Label ID="ItemSendingDownTypeIDLable" runat="server" CssClass="input" Text='<%#Eval("SendingDownTypeID") %>'/> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="SendingDownTypeIDTextBox" runat="server" MaxLength="3" CssClass="input" /> <asp:RequiredFieldValidator ID="SendingDownTypeIDTextBoxVali" runat="server" ControlToValidate="SendingDownTypeIDTextBox" Text="*" ValidationGroup="Tab1"/> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="??? ?????" HeaderStyle-HorizontalAlign="center"> <EditItemTemplate> <asp:TextBox ID="EditSendingDownTypeNameTextBox" runat="server" CssClass="input" Text='<%#Eval("SendingDownTypeName") %>'/> </EditItemTemplate> <ItemTemplate> <asp:Label ID="ItemSendingDownTypeNameLable" runat="server" CssClass="input" Text='<%#Eval("SendingDownTypeName") %>'/> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="SendingDownTypeNameTextBox" runat="server" MaxLength="50" CssClass="input"/> <asp:RequiredFieldValidator ID="SendingDownTypeNameTextBoxVali" runat="server" ControlToValidate="SendingDownTypeNameTextBox" Text="*" ValidationGroup="Tab1"/> </FooterTemplate> </asp:TemplateField> </Columns> <HeaderStyle BackColor="#61A6F8" Font-Bold="True" ForeColor="White" /> </asp:GridView> <asp:SqlDataSource ID="SendingDownTypeSqlDataSource" runat="server" ConflictDetection="OverwriteChanges" ConnectionString="<%$ ConnectionStrings:SqlConnectionString %>" DeleteCommand="DELETE FROM [SendingDownType_Table] WHERE [SendingDownTypeID] =@SendingDownTypeID" InsertCommand="IF NOT EXISTS (SELECT * FROM [SendingDownType_Table] WHERE [SendingDownTypeID] = @SendingDownTypeID ) INSERT INTO [SendingDownType_Table] ([SendingDownTypeID], [SendingDownTypeName]) VALUES (@SendingDownTypeID, @SendingDownTypeName) ELSE PRINT N'This Type ID Is Exist'" SelectCommand="SELECT [SendingDownTypeID], [SendingDownTypeName] FROM [SendingDownType_Table] ORDER BY [SendingDownTypeID], [SendingDownTypeName]" UpdateCommand="UPDATE [SendingDownType_Table] SET [SendingDownTypeName] = @SendingDownTypeName WHERE [SendingDownTypeID] = @SendingDownTypeID"> <DeleteParameters> <asp:Parameter Name="SendingDownTypeID" Type="Byte" /> </DeleteParameters> <InsertParameters> <asp:Parameter Name="SendingDownTypeID" Type="Byte" /> <asp:Parameter Name="SendingDownTypeName" Type="String" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="SendingDownTypeID" Type="Byte" /> <asp:Parameter Name="SendingDownTypeName" Type="String" /> </UpdateParameters> </asp:SqlDataSource> </asp:Panel> </td> </tr> <tr class="tabContainerTableRow"> <td><div class="clear"></div></td> </tr> </table> </ContentTemplate> </asp:UpdatePanel> </ContentTemplate> </asp:TabPanel> </asp:TabContainer>\[/code\]I try to pass a GridView ID to my JavaScript function that declared as follows:\[code\]'PrintGridView(Title,Address,Terms,GridViewName)'\[/code\]to use it in my ASP.NET page for \[code\]ImageButton\[/code\] on \[code\]OnClientClick\[/code\] Event as follows:\[code\]<asp:ImageButton ID="SendingDownTypePrintImageButton" runat="server" ImageUrl="~/images/printer.png" ToolTip="Print" OnClientClick="PrintGridView('university',' address','Terms','<%=SendingDownTypeGridView.ClientID%>')"/>\[/code\]but I always get an error. What should I do to solve this problem?
 
Back
Top