Click here to Skip to main content
14,936,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone,,

I have a html page named form.html where in i need to get the details like username and emailid from the user and insert into database.
So while inserting into database am posting the values to .aspx page and interacting with the database wherein am writing the backend code for interaction.Till then Everything is working fine.Now,My question is after successfull insertion of data into database i want to display a message to the user on form.html on basis of code written in aspx.cs page.Can this be worked out???
Please suggest me some solution...
Thanks in advance.......
Posted
Comments
[no name] 30-Aug-11 6:52am
   
Would be helpfull, if you post you code.
hitech_s 30-Aug-11 6:53am
   
r u using .cs or complete aspx page

You can redirect to the html page from your code behind and send you message in the query string.
   
Yes, it is possible, try this:

C#
int i=comm.ExecuteNonQuery();
if(i>0)
{
string script = "<script type=\"text/javascript\">alert('Your have been registered successfully!');</script>";
       Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", script);
}


hope it helps :)

for further queries comment here!
   
Comments
qwerty 2 5-Sep-11 5:16am
   
hi Uday...
this would pop up an alert but it will not get back to the html page where i have entered values...I mean aspx page should not be visible, it should take the values from html form and post the message on html form but for code behind i use .aspx and .cs files.
Response.Write will work, or you could add a label to the page and set it's Text property. I'd go with the later - it gives you better control over where the text will go.
   
you can generate an alert message
by writting a small javascript code
example

C#
string message ="Successfully inserted" ;
string script = "<script language="\"javascript\"type=\"text/javascript\"">;alert('"+ message + "');</script>"
ScriptManager.RegisterStartupScript(Page, this.GetType(),"AlertMessage", script, false);
   
v2
Comments
qwerty 2 5-Sep-11 5:17am
   
hi this would pop up an alert but it will not get back to the html page where i have entered values...I mean aspx page should not be visible, it should take the values from html form and post the message on html form but for code behind i use .aspx and .cs files.
Since you are using Html page to post details to Asp.Net Page, I assume you are using Ajax. JQuery Ajax provides attribute "success", In which you can perform your action once Ajax request gets complete.

You can perform DataSave operation on Page_Load Event of your Asp.Net Page. Then write "true" / "false" using Respons.Write based on result. And then display message in the Javascript function assigned to attribute "success".

You can refer below code for this.
JavaScript
<script language="javascript" type="text/javascript">
     
     function JqueryAjaxExample() {
         $.ajax({
            type: "POST",
            url: "JqueryExampleAjax.aspx",
            success: function (serverDate) {
                JqueryAjaxExampleResponse(serverDate);
            }
        });
    }
 
    function JqueryAjaxExampleResponse(result) {
            if(result=='true')
            {
              alert('Details saves successfully.);
            }
            else
            {
              alert('Failed to save.);
            }
        }
     
 
</script>


You can also refer below Article.
Simplifying Asp.Net Core Ajax
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900