Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with passing data to a masked textbox

Hi,

I am able to select data from a listbox and pass it to a regular textbox (ItemA) using the code below,

ItemA.Text = ListBox1.SelectedItem.Text

However the code doesn't work with a masked input box, how do modify the code to pass the value selected from a listbox to a masked input box? I am using ASP.NET.

V.
Avatar of Roopesh Reddy
Roopesh Reddy
Flag of India image

Hi,

Please check the below sample code!

<ajaxToolkit:ToolkitScriptManager runat="server" ID="scriptManager1">
    </ajaxToolkit:ToolkitScriptManager>

    <asp:TextBox runat="server" ID="txtBox"></asp:TextBox>

    <ajaxToolkit:MaskedEditExtender runat="server" ID="maskedTextBox" MaskType="Number" Mask="99.99" TargetControlID="txtBox">
    </ajaxToolkit:MaskedEditExtender> 

 
//Code behind - Initialing the value
protected void Page_Load(object sender, EventArgs e)
        {
            txtBox.Text = "11.11";
}

Open in new window


Hope it helps u...
Avatar of Victor  Charles

ASKER

Hi,

My problem is what is the correct code to pass it the data from the textbox to the listbox when the textbox is masked? The sample code does not tranfer the data the listbox.

Thanks.
Hi,

Check the sample code, which is working fine for me!

 <asp:TextBox runat="server" ID="txtBox"></asp:TextBox>

    <ajaxToolkit:MaskedEditExtender runat="server" ID="maskedTextBox" MaskType="Number" Mask="99.99" TargetControlID="txtBox">
    </ajaxToolkit:MaskedEditExtender> 


    <asp:ListBox runat="server" ID="listbox" >
        <asp:ListItem Text="text1" />
        <asp:ListItem Text="text2" />
    </asp:ListBox>

    <asp:Button runat="server" Text="Add" OnClick="btnClick" />

//Copy the Masked textbox data to Listbox
 protected void btnClick(object sender, EventArgs e)
        {
            listbox.Items.Add(txtBox.Text);
        }

Open in new window


Hope it helps u...
Sorry, I meant what is the proper code to copy selected item from a listbox to a Masked InputBox?
Hi,

Then try the following code!

Use the same code above, but the button click handler changed

 protected void btnClick(object sender, EventArgs e)
        {
            //Copy the selected value to Masked text box!
            txtBox.Text = listbox.SelectedValue;
        }

Open in new window


Hope it helps u...
I need the text, not the value. This code works when the input control is unmasked, any ideas why it does not work when the control is masked?

C1NSNA.Text = C1NSN.SelectedItem.Text

Thanks.
SOLUTION
Avatar of Roopesh Reddy
Roopesh Reddy
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Could not figure the answer from the link, contacted componentone. waitinf to hear bacl from them.