This is a migrated thread and some comments may be shown as answers.

Alert + text box value

4 Answers 447 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
vvvv
Top achievements
Rank 1
vvvv asked on 08 Feb 2014, 11:41 PM
Hi,
I give a scriptmanager alert message in a form if the textboxes I create using javascript are empty and return the page. It works fine by keeping all the values of all other fields except the value of one radtextbox value and upon click of ok in the alert box it displays the values back. Why does that happen?

Thanks

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Feb 2014, 05:03 AM
Hi,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadTextBox ID="RadTextBox1" runat="server">
</telerik:RadTextBox>
<telerik:RadButton ID="RadButton1" runat="server" Text="ShowValue" OnClick="RadButton1_Click">
</telerik:RadButton>

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    string script = "function f(){alertValue('" + RadTextBox1.Text + "'); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true); 
}

JavaScript:
<script type="text/javascript">
    function alertValue(value) {
        alert(value);
        $find("RadTextBox1").set_value("");
    }
</script>

Please provide your code if it doesn't help.
Thanks,
Shinu.
0
vvvv
Top achievements
Rank 1
answered on 10 Feb 2014, 04:54 PM
Thanks for replying back Shinu.
Here is the code where I handle the validation for textboxes I generate through Javascript. rtAdditionalInformation is the radtextbox which is not holding the value when the alert pops up. But the value is shown after the "ok" button of alert box is clicked. Thanks

 <telerik:RadTextBox ID="rtAdditionalInformation" runat="server" TextMode="MultiLine"
                    Rows="4" Columns="25">
                </telerik:RadTextBox>


aspx.cs
======
for (int i = 0; i < textboxvaluesLength; i++)
                    {
                        if (textboxvalues[i].Length <= 0)
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter a timeslot or remove the textbox')", true);
                            return;
                        }
                        else
                        {
                            textboxvalues[i] = textboxvalues[i].Substring(0, textboxvalues[i].Length - 3);
                        }
}
 addInfo = rtAdditionalInformation.Text;









0
Accepted
Shinu
Top achievements
Rank 2
answered on 11 Feb 2014, 03:34 AM
Hi,

Please have a look into the following code snippet which works fine at my end.

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    string value = rtAdditionalInformation.Text;
    string[] textboxvalues = new string[10];
    textboxvalues = value.Split(' ');
    string addInfo = string.Empty;
    for (int i = 0; i < textboxvalues.Length; i++)
    {
        if (textboxvalues[i].Length>= 0)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please enter a timeslot or remove the textbox')", true);
        }
        else
        {
            textboxvalues[i] = textboxvalues[i].Substring(0, textboxvalues[i].Length - 3);
        }
    }
    addInfo = rtAdditionalInformation.Text;
}

Thanks,
Shinu.
0
Singh
Top achievements
Rank 1
answered on 30 Jul 2017, 12:36 PM
thanks for code fine work 
Tags
General Discussions
Asked by
vvvv
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
vvvv
Top achievements
Rank 1
Singh
Top achievements
Rank 1
Share this question
or