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

Radconfirm add from CodeBehind

2 Answers 381 Views
Window
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 21 May 2012, 08:18 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 May 2012, 02:19 PM
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.
0
Brandon
Top achievements
Rank 1
answered on 23 May 2012, 01:31 AM
Thanks works well!
Tags
Window
Asked by
Brandon
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brandon
Top achievements
Rank 1
Share this question
or