Getting Javascript And Asp.net Interaction Together
Here's the definition of my ASP.NET GridView control: Copy
You can change the signature of this method to take additional parameters, e.g. itemName, and you could modify the js to alter the text that the popup is displaying (you would need to change your html a little, but no biggie). Have you inspected the source to see what it contains? It might already have the information you want to display.
EDIT
Played with this, and have a quick way to get this done. I'm using jquery.
- Change the popup html to be like so or similarm where the span is going to contain the additional data:
<divid="popupDiv"runat="server"align="center"class="confirm"style="display: none; background-color: white"><imgalign="absmiddle"src="Images/important.png" /><b>CONFIRM:</b> Delete <spanid="popupDescription"></span>?<br /><asp:ButtonID="btnOk"runat="server"Text="Yes"Width="50px" /><asp:ButtonID="btnNo"runat="server"Text="No"Width="50px" /></div>
- Update the button in your grid with a data=itemName="" attribute like below. Note my data class id called 'DataClass', and has a property called 'Name'. You can change this to match your data:
<asp:Button ID="btnDelete" runat="server" CommandArgument='<%# Container.DataItemIndex %>' ForeColor="Red" CommandName="DeleteReq"data-itemName="<%# ((DataClass)Container.DataItem).Name %>" OnClientClick="showConfirm(this); return false;" Text="Delete" />
- Finally, change your function to inject this value into the popup:
functionshowConfirm(source) {
//I use jquery to get the data-itemName attribute value and set it on the spanvar sourceElement = $(source);
var additionalInfo = sourceElement.attr('data-itemName');
var descriptionElement = $('#popupDescription');
descriptionElement.text(additionalInfo);
this._source = source;
this._popup = $find('mdlPopup');
this._popup.show(); // find the confirm ModalPopup and show it
}
Granted, this is far from an elegant solution, but it works.
Post a Comment for "Getting Javascript And Asp.net Interaction Together"