Radconfirm add from CodeBehind

3 posts, 1 answers
  1. Brandon
    Brandon avatar
    8 posts
    Member since:
    Nov 2010

    Posted 21 May 2012 Link to this post

    Hi Everyone,

    I have a scenario where I would like to use a Radconfirm but only if some server side validation warrants it.
    I am using a RadAjaxManager on a Masterpage.  I am using RadAjaxManagerProxy on the Page.

    Scenario:
    I have a Textbox and a Save RadButton.

    - Click Save Button
         < Server side check of Database to see if name already exists >

              1) Name already exists - Radconfirm will appear
                   - Yes - Perform Save
                   - No - close Confirm message

              2) Name does not exist
                   - Perform Save

    Any suggestions on how to achieve this would be much appreciated.

    Thanks

    Bran
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 May 2012 Link to this post

    Hi Brandon,

    Here is the sample code which I tried based on your scenario.
    aspx:
    <style type="text/css">
    .buttons
    {
        display:none;
    }
    </style>
    <telerik:RadTextBox ID="RadTextBox1" runat="server">
    </telerik:RadTextBox>
     <telerik:RadButton ID="RadButton1" runat="server" Text="Click" OnClick="RadButton1_Click"></telerik:RadButton>
    <telerik:RadWindowManager runat="server" ID="RadWindowManager1"></telerik:RadWindowManager>
    <asp:Button ID="Hdn" runat="server" OnClick="Hdn_Click" CssClass="buttons" />
    C#:
    protected void RadButton1_Click(object sender, EventArgs e)
        {
            SqlDataAdapter adapter = new SqlDataAdapter("SELECT FirstName FROM Employees WHERE FirstName='" + RadTextBox1.Text + "'", con);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            if (dt.Rows.Count != 0)
            {
                RadWindowManager1.RadConfirm("Perform save?", "confirmCallBackFn", 300, 100, null, "Name already exists");
            }
            else
            {
                con.Open();
                SqlCommand command = new SqlCommand("INSERT INTO table VALUES(. . .. ) ", con);
                command.ExecuteNonQuery();
                con.Close();
            }
        }
       
        protected void Hdn_Click(object sender, EventArgs e)
        {
            
            con.Open();
            SqlCommand command = new SqlCommand("INSERT INTO table VALUES(. . .. ) ", con);
            command.ExecuteNonQuery();
            con.Close();
        }
    JS:
    <script type="text/javascript">
        function confirmCallBackFn(arg) {
            if (arg == true) {
                var oButton = document.getElementById("Hdn");
                oButton.click();
            }
        }
    </script>

    Thanks,
    Shinu.
  3. Brandon
    Brandon avatar
    8 posts
    Member since:
    Nov 2010

    Posted 22 May 2012 Link to this post

    Thanks works well!
Back to Top