Link to home
Start Free TrialLog in
Avatar of dotnetpro
dotnetpro

asked on

Simple servier side validation and javascript alert

Experts,

I have a server side validation function that validates the duplicacy of textbox contents against database on textchanged event. I have keep this textbox in an updatepanel  control to avoid page refresh. I want a pop alert or message the moment validation fails on the textbox. Please tell me how to do that and any code sample will be a big help.
Avatar of suganthkumar
suganthkumar
Flag of India image

hi,

At the server side, once your validation is over, you can use the below code to put a clientside script to show a message.
ClientScript.RegisterStartupScript(this.GetType(), "someName", "alert('some message3333');", true);

Open in new window

Hi,

in the case of AJAX Update panel, you can use the "ScriptManager" object instead of "ClientScript"

Avatar of dotnetpro
dotnetpro

ASKER

This is what i did . Nothing happened

   


 protected void CheckDuplicateServices(object sender, EventArgs e)
    {
        if (dbq.CheckServices(txtnewservice.Text))
        {
          ClientScript.RegisterStartupScript(Page.GetType(), "msg", "alert('Service name already exists');",true);
        }
       

Open in new window

Hi,

if you are using AJAX and UpdatePanel, then ClientScript object has no effect. instead, you need to use the "ScriptManager" object.



protected void CheckDuplicateServices(object sender, EventArgs e)
    {
        if (dbq.CheckServices(txtnewservice.Text))
        {
          ScriptManager.RegisterStartupScript(this, Page.GetType(), "msg", "alert('Service name already exists');",true);
        }
       

Open in new window

Yaar, i have plugged this line of code nearly every where....but this thing is just not working.
I have plugged it in textchanged event of a textbox..nothing happened..because that is where i initially wanted to check the duplicacy...then i tried sticking it in btnsubmit_Click() event and there also it apparently did not work...so there has to be some thing of a size of blunder that i am doing because of which it is not happening...i know you are correct , i am the only one making this mistake..can you please correct me ???
Hi,

I have attached a sample work that i have done inside the ajax panel. please refer to it.

Regards
webform.zip
Its doing what its supposed to do...thanks for the nice sample...but the problem i have is that a user fills a textbox and i have to make a database call to verify whether that text already exists in the db ....If it does then pop up a message that the text already exists without a postback....This could either happen on the onblur event and the focus remains on the textbox text deleted from it or onclick event of submit button and textbox gets the focus with text deleted.....that is killing me...i am not able to do that..
ASKER CERTIFIED SOLUTION
Avatar of suganthkumar
suganthkumar
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