Hi Friends,
Am facing a problem in Modal popup. following is the source code

<div>
        <asp:Button runat="server" ID="hiddenTargetControlForModalPopup" Style="display: none" />
        <ajaxToolkit:ModalPopupExtender runat="server" ID="programmaticModalPopup" BehaviorID="programmaticModalPopupBehavior"
            TargetControlID="hiddenTargetControlForModalPopup" PopupControlID="programmaticPopup"
            BackgroundCssClass="modalBackground" DropShadow="True" PopupDragHandleControlID="programmaticPopupDragHandle"
            RepositionMode="RepositionOnWindowScroll">
        </ajaxToolkit:ModalPopupExtender>
        <asp:Panel runat="server" CssClass="modalPopup" ID="programmaticPopup" ScrollBars="auto"
            Height="300px" Style="display: none; width: 600px; padding: 10px">
       
            <div style="padding-top: 10px;">
              <asp:TextBox ID="TextBoxEdit" runat="server"></asp:TextBox>            </div>
            <div>
                <a runat="server" id="EditQuestion" class="button" href="#" onserverclick="EditQuestion_Click">
                    Update</a> <a id="hideModalPopupViaClientButton" class="button" href="#">Cancel</a>
            </div>
            <br />
        </asp:Panel>
    </div>

From below code am triggering the popup and also setting the intial value of TextBoxEdit .

protected void LinkButtonQuestionEdit_Click(object sender, EventArgs e)
        {
            LinkButton questionLink = (LinkButton)sender;
            QuestionBank question = business.GetQuestionById(int.Parse(questionLink.CommandArgument));
            TextBoxEdit.Text = question.Question;
                this.programmaticModalPopup.Show();
        }

from below code code am capturing the TextBoxEdit value but the value getting null.

protected void EditQuestion_Click(object sender, EventArgs e)
        {
            QuestionBank question = new QuestionBank();
            question.Question = TextBoxEdit.Text;
          business.UpdateQuestion(question);
            BindQuestionBankGrid();
            this.programmaticModalPopup.Hide();
        }

you can find the controls in modalpopup . am getting popup and am changing the value of TextBoxEdit. but in code behind TextBoxEdit is getting null After postback.
Even if we wont change then also the TextBoxEdit value will gets null value.

Please help me.

Dani AI

Generated

This looks like the classic ASP.NET lifecycle / viewstate problem rather than a bug in ModalPopup itself. For the textbox is filled server-side and the popup shown, but by the time the server click runs the textbox is empty. Typical causes: page data-binding or control initialization on every postback (Page_Load without an IsPostBack guard), using an HtmlAnchor as the submit control, or a partial postback/update-panel that does not include the modal controls or the submit trigger.

Practical fixes to try (apply one at a time and re-test):

  • Prevent re-binding on postback. Initialize grids and data only when not postback:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindQuestionBankGrid();
        }
    }
  • Use an ASP.NET button/linkbutton for the update so it performs a proper postback and participates in viewstate:

    <asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="EditQuestion_Click" />
  • If the page uses UpdatePanel, either put the modal panel inside the same UpdatePanel or add an async trigger for the update button so the textbox value is included in the partial postback.

Debug tips and cautions: set breakpoints and watch TextBoxEdit.Text in Page_Load and in EditQuestion_Click to see where it gets cleared; inspect Request.Form to confirm the browser actually sent the value; avoid server-side Visible=false for the panel (that removes controls from the page). As noted, switching to a client-side jQuery modal is an alternative, but fixing lifecycle/binding issues is the usual, minimal change.

why ajax Modal Popup. use jquery Modal popup
easy 2 use

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.