saving data in the database

  • Thread starter Thread starter Raymond Lewallen
  • Start date Start date
R

Raymond Lewallen

Nikhil,

I think what you are wanting to do is not use the javascript initially. You
will want to have your Button control set to runat=server, and when you
click it this buttons will fire a postback. You can then gather your
information from your form either putting the code in your sub that handles
MyButton.onClick or by having that same sub call a different sub that
gathers and saves the data. Then when you are done with your data, at the
end of your MyButton.onClick sub, use
RegisterStartupScript("callitwhatever","<script>window.close</script>") and
this will close your window.

Raymond Lewallen
 
Hi all,
I display a asp.net form with about 50 textboxes in a dialogbox. The
textboxes are bound to a dataset using <%# %>. The Dataset and the adapter
used to fill it - both are declared as protected on the class level. The
form displays data correctly. I also have an HTML server Button control to
submit the form. When the user clicks this button, I want to close the
dialog box and save the data. So I created a javascript function to close
the dialogbox and it is called using the onclick attribute of the button. It
works fine. But my question is how do I gather the form's data back into the
dataset? Is there a way to call second function( this would be server side
function) when the button is closed?

Thanks...
-Nikhil
 
Raymond, thanks.
Now using RegisterStartupScript allows me to close the window and handle
a server side event. But I still have the problem using the Dataset and
DataAdapter.
Here is the Button's click event handler. I get NullReferenceException on
the second line.private void btnSubmit_Click(object sender, System.EventArgs
e)
{

SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(
sqlAdapterProposals );


sqlAdapterProposals.Update(datasetProposals,"Proposals");


this.RegisterStartupScript("CloseWindow","<script>window.close</script>");

}

Thanks...
-Nikhil
 
Nikhil,

Where are you instantiating sqlAdapterProposals? The null reference sounds
like that is where the problem could be.
 
Nikhil,

Have you stepped throught the code to verify sqlAdapterProposals is being
instantiated on the postback, and perhaps put a breakpoint in line2 of your
private void btnSubmit_Click sub to see what the values of all objects
required are set to at that point. It still sounds like sqlAdapterProposals
is set to nothing when you're getting to that point. Your sqlAdapter
instantiation looks like this?: SqlDataAdapter sqlAdapterProposals = new
SqlDataAdapter();

Raymond Lewallen
 
Thanks.
The sqlAdapterProposals is declared as protected on class level but it is
instantiated in the Page_Load method.
 
Back
Top