Solved

ModalPopupExtender Textbox

Posted on 2010-11-09
5
632 Views
Last Modified: 2012-05-10
I have a update panel with textbox.  What is the best way to get the textbox string into a variable  that can be passed into a stored procedure using C#?
0
Comment
Question by:gdspeare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 34110028
Hi,

Not sure i fully understand your question but lets assume you need to get the value of a textbox nested inside an updatepanel into a string you would need to do something like:

Dim txt As TextBox = CType(UpdatePanel1.FindControl("TextBox1"), TextBox)
Dim strVariable As String = txt.Text.ToString()

You can then pass strVariable as a variable to your stored procedure.

/Carl.
0
 

Author Comment

by:gdspeare
ID: 34113999
thanks for the response.  

it makes sense what you are suggesting.  for some reason though my update panel is not firing when by button is selected.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head> 
   <script type="text/javascript">


function GetNotetext() {
    var myNoteField = document.getElementById('txt_Note');
    if (myNoteField.value != "")
       (myNoteField.value)
    else
       ("Would you please enter some text?")
}

</script>
<body>
    <form id="form1" runat="server">
    

    <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
           
    <asp:LinkButton ID="lbn_job_det" runat="server">View Job Details</asp:LinkButton>
        <ajaxtoolkit:modalpopupextender 
        id="ModalPopupExtender" 
        runat="server" 
        
        cancelcontrolid="btn_Cancel" 
        dropshadow="true" 
        okcontrolid="btn_OK" 
        popupcontrolid="Panel1" 
        popupdraghandlecontrolid="Panel3" 
        targetcontrolid="lbn_job_det" 
       > 
    </ajaxtoolkit:modalpopupextender>

  
    <asp:Panel ID="Panel1" runat="server" style="display:none" >
    <input type='text' id='txt_Note' />
    <input type='button' onclick='notEmpty()' value='Form Checker' />
    <asp:Button ID="btn_Cancel" runat="server" Text="Cancel" />
    <asp:Button ID="btn_OK" onclick="btn_Ok_OnClick" runat="server" Text="OK" />
    </asp:Panel>


    <div id="div_PassedValue">
        <asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
    </div>


    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    public void btn_Ok_OnClick(object sender, EventArgs e)
    {

        //TextBox2.Text = GetNoteText();
        string str_Note = Panel1.FindControl("txt_Note").ToString();
        TextBox2.Text = str_Note;
    }

  }

Open in new window

0
 
LVL 18

Accepted Solution

by:
carlnorrbom earned 500 total points
ID: 34115813
Hi,

That is because you're trying to run server side code with a button inside a modal panel. By design, server controls inside a modal panel looses their server side capabilities. There are ways around this however. For instance you can add a client attribute to the button in question that performs a postback and then check in the page_load event for the __EVENTTARGET and if it's the button then grab the value of the textbox. I don't have access to my dev box right now (on the iPad...) but can maybe provide a sample tomorrow.

/Carl.
0
 
LVL 18

Expert Comment

by:carlnorrbom
ID: 34115832
Hi,

Just one more thing, for future reference. An updatepanel and a modalpanel are two completely different things.

/Carl.
0
 

Author Closing Comment

by:gdspeare
ID: 34155560
Thanks for the education.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question