views:

277

answers:

1

I have a button inside of a gridview's template field. Onclick i want to the button to open up a modal popup while force updating the updatepanel and formview inside the modal popup because the formview's datasource depends on a hidden field in which i am setting after click also.

This is what i have so far.

protected void bttnEdit_Click2(object sender, ImageClickEventArgs e)
{
    ImageButton bttnEdit = (ImageButton)sender;

    HiddenField HiddenField1 = (HiddenField)FormView1.FindControl("HiddenField1");
    HiddenField1.Value = bttnEdit.CommandArgument;

    UpdatePanel UpdatePanel3 = (UpdatePanel)FormView1.FindControl("UpdatePanel3");


    AjaxControlToolkit.ModalPopupExtender ModalPopupExtender1 = (AjaxControlToolkit.ModalPopupExtender)FormView1.FindControl("ModalPopupExtender1");
    ModalPopupExtender1.Show();
    FormView3.DataBind();
    UpdatePanel3.Update();

}

I see the popup but nothing on the inside loads. What am I doing wrong?

<asp:TemplateField ShowHeader="False">
    <EditItemTemplate>
    </EditItemTemplate>
    <ItemTemplate>
        <asp:UpdatePanel ID="UpdatePanel21" runat="server">
            <ContentTemplate>
                <asp:ImageButton ID="bttnEdit" CommandArgument = '<%# Eval("Id") %>' runat="server" OnClick ="bttnEdit_Click2" injid='<%# Eval("Id") %>' causeid='<%# Eval("C_Type") %>' natureid='<%# Eval("n_type") %>' CausesValidation="False" ImageUrl="~/images/bttnEdit.gif" Text="Edit" OnClientClick ="loadmodal(this.injid,this.causeid,this.natureid);"  />
            </ContentTemplate>
        </asp:UpdatePanel>
        &nbsp;<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" CommandName="Delete" ImageUrl="~/images/bttnDelete.gif" Text="Delete" />
    </ItemTemplate>


<asp:Panel ID = "Pnlmodal" runat ="server" style="background-color:White; padding:1em 6px;">  
    <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode ="Conditional" ChildrenAsTriggers ="true"   >
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID ="Button1" EventName ="Click" />
        </Triggers>
    <ContentTemplate>
        <asp:FormView ID="FormView2" runat="server" DefaultMode ="Edit" DataSourceID ="SqlDataSource8">
            <EditItemTemplate>
                <table>
                    <tr>
                        <td colspan="2" align="center" style="color:Blue;font-size:large">Edit Injury</td>
                    </tr>
                    <tr>
                        <td align="right" ><strong>What event caused the injury </strong></td>                 
                        <td align="left">                                                                                                                <asp:UpdatePanel ID="UpdatePanel14" runat="server">
                                 <ContentTemplate>
                                     ////stuff
                                 </ContentTemplate>
                             </UpdatePanel>
A: 

Your FormView in your modal is named FormView2 however your code Databinds FormView3. Could you happenly be binding the wrong FormView

jmein
You're right. I fixed that. however i'm still having the same issue.
Eric
I highly recommend meaningful names for your controls it will make it easier to avoid these types of situations. Just add a prefix such as upl_ for your UpdatePanels and fmv_ for your formviews then add what they are for at the end of the variable
jmein
Is UpdatePanel3 inside FormView1? I can't tell from the code you have shown
jmein
@Jmein Yes it is inside of Formview1. And you're - readability is very important. Time didn't allow it for this project though.
Eric
That formview is wrapped in an updatepanel. When i wrapped it in the updatepanel this is when I started getting this error.
Eric
I understand but thinking of good variables names can improve not only readability but avoid time-consuming mistakes of placing the wrong variable names and having to sort through it all.
jmein
@Jmein. Thanks. I figured out my issue. Haha, and it is absolutely because I mixed up variable names. I got to get better at that. Lesson learned. thanks.
Eric
Your welcome. It is always worth the extra couple minutes to come up with good variable names. ;)
jmein