button control

Last post 08-01-2007 6:28 AM by addie. 4 replies.

Sort Posts:

  • button control

    07-31-2007, 10:01 PM
    • Member
      45 point Member
    • Tweety@net
    • Member since 07-31-2007, 4:39 AM
    • Posts 179

    Hi,

    im designing a form in asp.net using AJAX tool kit.

    i have one button control and text box in my form.i added sql data source also.

    when i clik button the value entered in text box must store in DB.

    this is my code..

    <form id="form1" runat="server">

    <div>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    <asp:Button ID="Button1" runat="server" Text="Button" />

    <asp:SqlDataSource ID="S1" runat="server" ConnectionString="<%$ ConnectionStrings:onlineshop %>"

    SelectCommand="master" SelectCommandType="StoredProcedure">

    <%--<SelectParameters>

    <asp:ControlParameter Name="state" ControlID="button1" />

    </SelectParameters>--%></asp:SqlDataSource>

     

    </div>

    </form>

     now im not clear about how can i make link between this data source and button control,since i couldnt able to use datasourceID property in asp:button control.

    Thanks for any reply

     

  • Re: button control

    08-01-2007, 2:02 AM
    • Participant
      1,562 point Participant
    • addie
    • Member since 03-02-2007, 6:12 AM
    • Posts 291

    First you need to have a UpdateCommand specified for your SqlDataSource, something like below:
     

    <asp:SqlDataSource
              id="SqlDataSource1"
              runat="server"
              ConnectionString="<%$ ConnectionStrings:YourConnectionString%>"
              SelectCommand="SELECT EmployeeID, LastName, Address FROM Employees"
              UpdateCommand="UPDATE Employees SET Address=@Address WHERE EmployeeID=@EmployeeID">
              <UpdateParameters>
                  <asp:ControlParameter Name="Address" ControlId="TextBox1" PropertyName="Text"/>
                  <asp:ControlParameter Name="EmployeeID" ControlId="DropDownList1" PropertyName="SelectedValue"/>
              </UpdateParameters>
    </asp:SqlDataSource>
    

     

    and then on the click event of your button need to call SqlDataSource1.Update() method.
    You can refer to the tutorial at: http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.update.aspx

  • Re: button control

    08-01-2007, 2:12 AM
    • Member
      45 point Member
    • Tweety@net
    • Member since 07-31-2007, 4:39 AM
    • Posts 179

    Thanks for the guidance,

    but using sql data source, i have to call procedure ,not select or update..

    and also how can i do this without using sqldatasource? 

     

     

  • Re: button control

    08-01-2007, 2:54 AM
    • Member
      45 point Member
    • Tweety@net
    • Member since 07-31-2007, 4:39 AM
    • Posts 179

    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="HRMIS_07.WebForm1" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <%@Import Namespace="System.Data" %>

    <%@Import Namespace="System.Data.Common" %>

    <%@Import Namespace="System.Diagnostics" %>

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>Untitled Page</title>

    <script runat="server">

    Sub fncsave(ByVal sender As Object, ByVal e As EventArgs)

    'Dim a As SqlDataSourceCommandEventArgs

    'Dim com As DbCommand

    'Dim con As DbConnection

    'Dim ts As DbTransaction

    'com = a.Command

     

    'con = com.Connection

    'con.Open()

    'ts = con.BeginTransaction

    'com.Transaction = ts

     

     

    S1.Update() //////// im not sure in calling this update method....wats the exact code???

     

     

     

    End Sub

     

    </script>

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick ="fncsave();return false;" />

    <asp:SqlDataSource ID="S1" runat="server" ConnectionString="<%$ ConnectionStrings:student %>"

    SelectCommand="master" SelectCommandType="StoredProcedure">

    </asp:SqlDataSource>

     

    </div>

    </form>

    </body>

    </html>

  • Re: button control

    08-01-2007, 6:28 AM
    Answer
    • Participant
      1,562 point Participant
    • addie
    • Member since 03-02-2007, 6:12 AM
    • Posts 291

    using sql data source, i have to call procedure ,not select or update..

    I guess you mean you will execute stored procedures to select and display data and also one to save data. Do as below:

     

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:AllTestConnectionString %>"
        UpdateCommand="sp_test" UpdateCommandType="StoredProcedure">
        <UpdateParameters>
        <asp:Parameter Name="" Type="" />
        <asp:Parameter Name="" Type="" />
        </UpdateParameters>
    </asp:SqlDataSource>
     
    put in the names of the stored procedure, parameters their types etc

    im not sure in calling this update method....wats the exact code???

    that will be the id of the SqlDataSource object (say s1) dot Update, ie, s1.Update(); in the button click event.

     

Page 1 of 1 (5 items)