I have to display a popup when user clicks on Place button inside a gridview and please remeber it that as user clicks the Place button, i have to capture the value of commandArgument in a module level variable so that i can update it in Database.
Now as and when page displays and user clicks the Place button the page postback to server and then popup appears and at the same time i capture the value of commandargument of button in code behind. But, after the first click that is from 2nd time click of button displays the popup without sending the page on server. That is it’s not firing the onClick event of Place button and the value in module level variable remains unchanged. After that if user selects Ok button from popup it updates the value which sets in the module level variable when the Place button called at first.
What should i do?
Is there any mistake in my code?
<GridView id= "Grd" runat="server" AutoGenerateColumns="false" CssClass="GridStyle"
HeaderStyle-Font-Size="Small" Width="960" Visible="false">
<Columns>
'Columns goes here
<asp:TemplateField HeaderText="Action" HeaderStyle-Width="310px" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click"
CommandArgument='<%#Eval("intHireEnquiryID") %>' />
<asp:Button ID="btnPlace" runat="server" Text="Place" OnClick="btnPlace_Click"
CommandArgument='<%#Eval("intHireEnquiryID") %>' />
<ajaxtk:ModalPopupExtender runat="server" ID="actPopup" TargetControlID="btnPlace"
PopupControlID="pnlPopup" CancelControlID="btnCancel" >
</ajaxtk:ModalPopupExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</GridView>
InPanel i have two buttons PlaceFinal and Cancel which are used to Finally place and cancel the request.
In Code Behind i call it as : –
Dim popup As New AjaxControlToolkit.ModalPopupExtender
Dim i As Integer
For i = 0 To Grd.Rows.Count - 1
popup = Grd.Rows(i).FindControl("actPopup")
popup.Show()
Next
pnlPopup.Visible = True
Is there any attribute or anything else which i am missing so that the Place button onclick event not firing from second click onwards. Then why it’s working for first click?
The onclick event of button works only at first time and not after that.
Remove the modalpopupextender which was taken inside gridview and keep it in an update panel like below and remember remove the TargetControlId of modalpopupextender from actual button to a dummy button which has no use on the page and hide it. This btnDummy is only to remove the bug of raising error when targetcontrolid is not defined for modalpopup and nothing.
The Css class is as: –
Code behind: –
Thus it works great and fine.
Points to remember: –
But remember to remove the TargetControlId of modalpopupextender from actual button to a dummy button which has no use on the page and hide it. And do not set visible property of panel which has to show to true or false. It will handle automatically by ajaxmodalpopupextender.
Actually why i took a dummy button as targetcontrolid of modalpopup because i need to postback the page partially to update the generated list of radiobuttons. but if we take the main button as targetcontrolid then the default behaviour of button will be overridden by modalpopup extender and it will not postback the page. So, i took a dummy button. And on the actual button click event i generate the list and bind it to radiobuttonlist and then called the update method of update panel and then called the show method of modalpopup.
It’s fine now….
Thanks!!