Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Button Commands ASP.Net 2005 C#

Posted on 2008-06-25
6
Medium Priority
?
284 Views
Last Modified: 2013-12-16
Hi,

I would to have more than one funnction running when the button btnPrint_Click1 is clicked.

I have attached the code. At the moment i would like btnPrint_Click1 to do the same function that btnSave_Click1 does, which is adding data into the database.

So when clicking on the btnPrint_Click1, i would like it to send an email, and add data into the database.

Any help will be appareciated. I am using Visual Studio .Net 2005 in C#

introlux
===================================================================
ASPX
===================================================================
 
<script runat="server" language="C#">
 
 
 
    OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\\ProCom.mdb");
    OleDbCommand objCmd; 
        string sqlCmd; 
 
    void btnSave_Click1(Object s, EventArgs e)
    {
        sqlCmd = "INSERT INTO tblProCom (Pid, PName, ICD_IDF, PType, CName, PContact, SContact, NumSurvey, WNumber, Market, Languages, EstSurvLen, TotNoQues, SampSource, SampCri, TargNoComp, TargNoQuo_Mark, InciRate, CPCIR, FStart, FFinish, ProvOfQues, TestLink, FDataDel, Livewire, NumIntDataSet, Other, FDataSet, Tables, CodFrameGen, Coding, DataMerg, Ques, Stim, Samp, Soli, DPSpec) VALUES (@Pid, @PName, @ICD_IDF, @PType, @CName, @PContact, @SContact, @NumSurvey, @WNumber, @Market, @Languages, @EstSurvLen, @TotNoQues, @SampSource, @SampCri, @TargNoComp, @TargNoQuo_Mark, @InciRate, @CPCIR, @FStart, @FFinish, @ProvOfQues, @TestLink, @FDataDel, @Livewire, @NumIntDataSet, @Other, @FDataSet, @Tables, @CodFrameGen, @Coding, @DataMerg, @Ques, @Stim, @Samp, @Soli, @DPSpec)";
        OleDbCommand objCmd = new OleDbCommand(sqlCmd, objConn);
        objCmd.Parameters.Add("@Pid", txtPid.Text);
        objCmd.Parameters.Add("@PName", txtPName.Text);
        objCmd.Parameters.Add("@ICD_IDF", ICD_IDFDrop.SelectedValue);
        objCmd.Parameters.Add("@PType", pTypeDrop.SelectedValue);
        objCmd.Parameters.Add("@CName", txtCName.Text);
        objCmd.Parameters.Add("@PContact", txtPContact.Text);
        objCmd.Parameters.Add("@SContact", txtSContact.Text);
        objCmd.Parameters.Add("@NumSurvey", txtNumSurvey.Text);
        objCmd.Parameters.Add("@WNumber", txtWNumber.Text);
        objCmd.Parameters.Add("@Market", txtMarket.Text);
        objCmd.Parameters.Add("@Languages", txtLanguages.Text);
        objCmd.Parameters.Add("@EstSurvLen", txtEstSurvLen.Text);
        objCmd.Parameters.Add("@TotNoQues", txtTotNoQues.Text);
        objCmd.Parameters.Add("@SampSource", txtSampSource.Text);
        objCmd.Parameters.Add("@SampCri", txtSampCri.Text);
        objCmd.Parameters.Add("@TargNoComp", txtTargNoComp.Text);
        objCmd.Parameters.Add("@TargNoQuo_Mark", txtTargNoQuo_Mark.Text);
        objCmd.Parameters.Add("@InciRate", txtInciRate.Text);
        objCmd.Parameters.Add("@CPCIR", txtCPCIR.Text);
        objCmd.Parameters.Add("@FStart", txtFStart.Text);
        objCmd.Parameters.Add("@FFinish", txtFFinish.Text);
        objCmd.Parameters.Add("@ProvOfQues", txtProvOfQues.Text);
        objCmd.Parameters.Add("@TestLink", txtTestLink.Text);
        objCmd.Parameters.Add("@FDataDel", txtFDataDel.Text);
        objCmd.Parameters.Add("@Livewire", LivewireDrop.SelectedValue);
        objCmd.Parameters.Add("@NumIntDataSet", txtNumIntDataSet.Text);
        objCmd.Parameters.Add("@Other", txtOther.Text);
        objCmd.Parameters.Add("@FDataSet", txtFDataSet.Text);
        objCmd.Parameters.Add("@Tables", TablesDrop.SelectedValue);
        objCmd.Parameters.Add("@CodFrameGen", CodFrameGenDrop.SelectedValue);
        objCmd.Parameters.Add("@Coding", txtCoding.Text);
        objCmd.Parameters.Add("@DataMerg", txtDataMerg.Text);
        objCmd.Parameters.Add("@Ques", QuesDrop.SelectedValue);
        objCmd.Parameters.Add("@Stim", StimDrop.SelectedValue);
        objCmd.Parameters.Add("@Samp", SampDrop.SelectedValue);
        objCmd.Parameters.Add("@Soli", SoliDrop.SelectedValue);
        objCmd.Parameters.Add("@DPSpec", DPSpecDrop.SelectedValue);     
 
        objConn.Open();
        objCmd.ExecuteNonQuery();
        objConn.Close();
 
        Response.Redirect("Default.aspx");
}
</script>
 
=============================================================
CS File
=============================================================
 
    protected void btnPrint_Click1(Object s, EventArgs e)
    {
        MailAddress FromAddress = new MailAddress("project@theidfactor.com");
        MailAddress ToAddress = new MailAddress("project@theidfactor.com");
        MailMessage message = new MailMessage(FromAddress, ToAddress);
        message.Subject = "New Project Has been commissioned";
        message.Body = txtPName.Text + "Has now been commissioned";
        SmtpClient client = new SmtpClient("mail.tmnplc.com", 25);
        client.Send(message);
 
        Response.Redirect("Default.aspx");
    }
 
    protected void btnClear_Click1(object sender, EventArgs e)
    {
 
    }
    protected void btnSave_Click1(object sender, EventArgs e)
    {
    }

Open in new window

CreateProCom.txt
CreateProCom.aspx.txt
0
Comment
Question by:introlux
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 5

Expert Comment

by:JuckMan
ID: 21868455
move your btnSave_Click1 to the code behind file and call this from btnPrint_Click1 method. This seems like trivial ..Hope this helps
0
 

Author Comment

by:introlux
ID: 21872687
How do I call the method from btnPrint_Click1??
0
 
LVL 5

Accepted Solution

by:
rendaduiyan earned 1500 total points
ID: 21872755
private void sendMail()
{
         MailAddress FromAddress = new MailAddress("project@theidfactor.com");
        MailAddress ToAddress = new MailAddress("project@theidfactor.com");
        MailMessage message = new MailMessage(FromAddress, ToAddress);
        message.Subject = "New Project Has been commissioned";
        message.Body = txtPName.Text + "Has now been commissioned";
        SmtpClient client = new SmtpClient("mail.tmnplc.com", 25);
        client.Send(message);
 
        Response.Redirect("Default.aspx");

}
private void saveData()
{
   .....
}



private void otherTask()
{
....
}

protected void btnPrint_Click1(Object s, EventArgs e)
{
     sendMail();
     saveData();
     otherTask();
}
0
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 

Author Comment

by:introlux
ID: 21872872
That is working fine, but after doing this alteration, I am receiving the following error:

Compiler Error Message: CS0128: A local variable named 'objCmd' is already defined in this scope

Source Error:

 

Line 29:
Line 30:         sqlCmd = "INSERT INTO tblProCom (Pid, PName, ICD_IDF, PType, CName, PContact, SContact, NumSurvey, WNumber, Market, Languages, EstSurvLen, TotNoQues, SampSource, SampCri, TargNoComp, TargNoQuo_Mark, InciRate, CPCIR, FStart, FFinish, ProvOfQues, TestLink, FDataDel, Livewire, NumIntDataSet, Other, FDataSet, Tables, CodFrameGen, Coding, DataMerg, Ques, Stim, Samp, Soli, DPSpec) VALUES (@Pid, @PName, @ICD_IDF, @PType, @CName, @PContact, @SContact, @NumSurvey, @WNumber, @Market, @Languages, @EstSurvLen, @TotNoQues, @SampSource, @SampCri, @TargNoComp, @TargNoQuo_Mark, @InciRate, @CPCIR, @FStart, @FFinish, @ProvOfQues, @TestLink, @FDataDel, @Livewire, @NumIntDataSet, @Other, @FDataSet, @Tables, @CodFrameGen, @Coding, @DataMerg, @Ques, @Stim, @Samp, @Soli, @DPSpec)";
Line 31:         OleDbCommand objCmd = new OleDbCommand(sqlCmd, objConn);
Line 32:         objCmd.Parameters.Add("@Pid", txtPid.Text);
Line 33:         objCmd.Parameters.Add("@PName", txtPName.Text);
 
0
 

Author Comment

by:introlux
ID: 21873026
?????
0
 

Author Closing Comment

by:introlux
ID: 31470651
Thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question