如何通过ModelPopup获取数据列表项的用户输入. [英] How to get user-input through ModelPopup for the Datalist items.

查看:54
本文介绍了如何通过ModelPopup获取数据列表项的用户输入.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据列表来显示产品列表.
当用户单击任何产品时,将弹出带有
的弹出窗口 一个Label(ProductName),一个文本框和一个OkButton.到这里为止正在工作.
但是单击确定"按钮后,我无法从文本框中获取用户输入.
每次都返回文本框的初始默认值.

-------------------------------------------------- -----------------------------------------

I have a datalist to display Listof Product.
When user click on any of the product a Pop-up will open with
a Label(ProductName), a textbox and a OkButton. Upto here it is working.
But I am unable to get the user input from the textBox after clicking OK button.
It is returning the initial default value of textbox every time.

-------------------------------------------------------------------------------------------

<asp:DataList ID="DataList1" runat="server"

            onitemdatabound="DataList1_ItemDataBound">

        <asp:LinkButton ID="LinkButton1" runat="server" Text ='<%# Bind("pro_Name")%>'></asp:LinkButton>
        <asp:Panel ID="panel_Popup" runat="server" Width ="200" Height ="200" style ="background-color :Lime; display :none ">
            <asp:Label ID="lblProduct" runat="server" Text='<%# Bind("pro_Name")%>'></asp:Label>
            <asp:TextBox ID="ModelTxt" runat="server" TextMode ="SingleLine" Text ="Enter a Text"></asp:TextBox>
            <asp:Button ID="OkButton" runat="server" Text="Ok" />
            <asp:Button ID="CancelButton" runat="server" Text="Cancel" />
        </asp:Panel>
        <cc1:ModalPopupExtender ID="ModalPopupExtender2"  runat="server" TargetControlID ="LinkButton1"

        PopupControlID ="panel_Popup" BackgroundCssClass ="modelbackground" OkControlID ="OkButton"

        CancelControlID ="CancelButton" >


        </asp:DataList>
----------------------------------------------------------------------------------------
 protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        switch (e.Item.ItemType)
        {
            case ListItemType.AlternatingItem:
            case ListItemType.Item:
                 Button btn = (Button)e.Item.FindControl("OkButton");
                TextBox txt = (TextBox)e.Item.FindControl("ModelTxt");
                btn.Attributes.Add("onclick", "alert('" + txt.Text + "'); return false;");
                break;
        }
    }
-----------------------------------------------------------------------------------------



请帮助我填充一个完美的弹出窗口,以接受用户输入的数据列表项.



Please help me to populate a perfect popup window to accept user input for the datalist items.

推荐答案

您好,

您以静态方式将当前txt值分配给警报. Javascript在客户端运行.因此,将您的代码更改为

btn.Attributes.Add("onclick", "alert(document.getElementById(''" + txt.ClientID + "'').value); return false;");

动态获取价值

要获取在弹出窗口中输入的ModelTxt框的值,可以获取Submit事件后面的代码.按下提交按钮(将asp:button控件添加到aspx并在其click事件中)...具有此代码
Hi

You are assign the current txt value to the alert in a static way. Javascript run at client side. So change your code to

btn.Attributes.Add("onclick", "alert(document.getElementById(''" + txt.ClientID + "'').value); return false;");

to get the value dynamically

To get the values of the ModelTxt box entered in the pop can be get in the code behind on the submit event. Once press the submit button (add a asp:button control to the aspx and in its click event)...have this code
protected void Button1_Click(object sender, EventArgs e)
{
    Control ctrl=null;
    foreach (DataListItem Item in DataList1.Items)
    {
            ctrl = Item.FindControl("ModelTxt");

            if (ctrl !=null)
            {
                TextBox text1 = (TextBox)ctrl;
                string txt_entered_in_popup = text1.Text;
            }
        }



}


这篇关于如何通过ModelPopup获取数据列表项的用户输入.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆