Server side functionality

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reetu

    #1

    Server side functionality

    Hi All,

    I have an html button on .aspx page.

    <INPUT class="sbttn" id="btnComplete 0" onclick="onComp lete
    ()" type="button" value="Mark Completed"
    name="btnComple te0">

    When the user clicks on the html button the OnComplete
    function is called.

    <script language="javas cript">
    function onComplete()
    {

    // Client side code

    // Clicking the server control via code
    WorkItemForm.bt nComplete.click ();

    }
    </script>


    I need to perform some server side functinality whenever
    user clicks the html button. So I place a hidden server
    control (id = btnComplete) on the .aspx page. In the
    client side code I automatically click the server control
    ( WorkItemForm.bt nComplete.click ();).

    On the click event of hidden server control, I write the
    server side code in .aspx.cs page.

    // Code in .aspx.cs page

    private void btnComplete_Cli ck(object sender,
    System.EventArg s e)
    {
    // Calling Server Side Code
    }

    I am using btnComplete server control as an intermediate
    to perform server side functionality.

    Problem:

    I want to get rid of server control.
    Is there a way to perform server side functionality
    directly without using server control.

    I tried document.FormNa me.Submit();

    This doesn't work. Is there some other way to do so?

    Thanks & Regards,
    -Reetu








  • Ken Cox [Microsoft MVP]

    #2
    Re: Server side functionality

    Hi Reetu,

    Here's some VB code that might help you. It uses the submit() method. Not sure
    why it didn't work for you.

    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArg s) _
    Handles MyBase.Load
    Literal1.Text = "<script>functi on
    onCompleted(){a lert('action'); document.forms[0].submit();}</script>"
    If IsPostBack Then
    Label2.Text = "I was posted back at: " & Now.TimeOfDay.T oString
    End If
    End Sub


    <form id="Form1" method="post" runat="server">
    <p>
    <asp:textbox id="TextBox1" runat="server"> </asp:textbox></p>
    <p>
    <asp:label id="Label2" runat="server"> </asp:label></p>
    <p>
    <asp:label id="Label1" runat="server"> </asp:label></p>
    <p>
    <asp:literal id="Literal1" runat="server"> </asp:literal></p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <input class="sbttn" id="btnComplete 0" onclick="onComp leted()"
    type="button" value="Mark Completed"
    name="btnComple te0">
    </form>


    "Reetu" <reetu@ascentn. com> wrote in message
    news:06c901c35c 60$5aabcc10$a30 1280a@phx.gbl.. .
    Hi All,

    I have an html button on .aspx page.

    <INPUT class="sbttn" id="btnComplete 0" onclick="onComp lete
    ()" type="button" value="Mark Completed"
    name="btnComple te0">

    When the user clicks on the html button the OnComplete
    function is called.

    <script language="javas cript">
    function onComplete()
    {

    // Client side code

    // Clicking the server control via code
    WorkItemForm.bt nComplete.click ();

    }
    </script>


    I need to perform some server side functinality whenever
    user clicks the html button. So I place a hidden server
    control (id = btnComplete) on the .aspx page. In the
    client side code I automatically click the server control
    ( WorkItemForm.bt nComplete.click ();).

    On the click event of hidden server control, I write the
    server side code in .aspx.cs page.

    // Code in .aspx.cs page

    private void btnComplete_Cli ck(object sender,
    System.EventArg s e)
    {
    // Calling Server Side Code
    }

    I am using btnComplete server control as an intermediate
    to perform server side functionality.

    Problem:

    I want to get rid of server control.
    Is there a way to perform server side functionality
    directly without using server control.

    I tried document.FormNa me.Submit();

    This doesn't work. Is there some other way to do so?

    Thanks & Regards,
    -Reetu









    Comment

    • Ram

      #3
      Re: Server side functionality

      When your page is loaded, checl the HTML source of your page. Your
      hidden button will not be rendered at all.

      Instead, you can convert your button to a aspx button and add
      Javascript event to it from the code behind using

      Add this line of code to your page load event.
      ButtonName.Attr ibutes.add("onC lick","return onComplete()")

      Now when you click on your button it will raise the onclick event on
      the client side and will call onComplete Javascript function. Inside
      the Javascript if you return false, the form will not be submitted and
      the server side event of your button will not fire. If you return
      true, form will be submitted to the server and your button's onclick
      event will be fired on the server.

      ----
      Ram

      "Reetu" <reetu@ascentn. com> wrote in message news:<06c901c35 c60$5aabcc10$a3 01280a@phx.gbl> ...[color=blue]
      > Hi All,
      >
      > I have an html button on .aspx page.
      >
      > <INPUT class="sbttn" id="btnComplete 0" onclick="onComp lete
      > ()" type="button" value="Mark Completed"
      > name="btnComple te0">
      >
      > When the user clicks on the html button the OnComplete
      > function is called.
      >
      > <script language="javas cript">
      > function onComplete()
      > {
      >
      > // Client side code
      >
      > // Clicking the server control via code
      > WorkItemForm.bt nComplete.click ();
      >
      > }
      > </script>
      >
      >
      > I need to perform some server side functinality whenever
      > user clicks the html button. So I place a hidden server
      > control (id = btnComplete) on the .aspx page. In the
      > client side code I automatically click the server control
      > ( WorkItemForm.bt nComplete.click ();).
      >
      > On the click event of hidden server control, I write the
      > server side code in .aspx.cs page.
      >
      > // Code in .aspx.cs page
      >
      > private void btnComplete_Cli ck(object sender,
      > System.EventArg s e)
      > {
      > // Calling Server Side Code
      > }
      >
      > I am using btnComplete server control as an intermediate
      > to perform server side functionality.
      >
      > Problem:
      >
      > I want to get rid of server control.
      > Is there a way to perform server side functionality
      > directly without using server control.
      >
      > I tried document.FormNa me.Submit();
      >
      > This doesn't work. Is there some other way to do so?
      >
      > Thanks & Regards,
      > -Reetu[/color]

      Comment

      • Reetu

        #4
        Re: Server side functionality


        Thanks a lot, it works.

        Regards,
        -Reetu
        [color=blue]
        >-----Original Message-----
        >When your page is loaded, checl the HTML source of your[/color]
        page. Your[color=blue]
        >hidden button will not be rendered at all.
        >
        >Instead, you can convert your button to a aspx button and[/color]
        add[color=blue]
        >Javascript event to it from the code behind using
        >
        >Add this line of code to your page load event.
        >ButtonName.Att ributes.add("on Click","return onComplete()")
        >
        >Now when you click on your button it will raise the[/color]
        onclick event on[color=blue]
        >the client side and will call onComplete Javascript[/color]
        function. Inside[color=blue]
        >the Javascript if you return false, the form will not be[/color]
        submitted and[color=blue]
        >the server side event of your button will not fire. If[/color]
        you return[color=blue]
        >true, form will be submitted to the server and your[/color]
        button's onclick[color=blue]
        >event will be fired on the server.
        >
        >----
        >Ram
        >
        >"Reetu" <reetu@ascentn. com> wrote in message[/color]
        news:<06c901c35 c60$5aabcc10$a3 01280a@phx.gbl> ...[color=blue][color=green]
        >> Hi All,
        >>
        >> I have an html button on .aspx page.
        >>
        >> <INPUT class="sbttn" id="btnComplete 0"[/color][/color]
        onclick="onComp lete[color=blue][color=green]
        >> ()" type="button" value="Mark Completed"
        >> name="btnComple te0">
        >>
        >> When the user clicks on the html button the OnComplete
        >> function is called.
        >>
        >> <script language="javas cript">
        >> function onComplete()
        >> {
        >>
        >> // Client side code
        >>
        >> // Clicking the server control via code
        >> WorkItemForm.bt nComplete.click ();
        >>
        >> }
        >> </script>
        >>
        >>
        >> I need to perform some server side functinality[/color][/color]
        whenever[color=blue][color=green]
        >> user clicks the html button. So I place a hidden server
        >> control (id = btnComplete) on the .aspx page. In the
        >> client side code I automatically click the server[/color][/color]
        control[color=blue][color=green]
        >> ( WorkItemForm.bt nComplete.click ();).
        >>
        >> On the click event of hidden server control, I write[/color][/color]
        the[color=blue][color=green]
        >> server side code in .aspx.cs page.
        >>
        >> // Code in .aspx.cs page
        >>
        >> private void btnComplete_Cli ck(object sender,
        >> System.EventArg s e)
        >> {
        >> // Calling Server Side Code
        >> }
        >>
        >> I am using btnComplete server control as an[/color][/color]
        intermediate[color=blue][color=green]
        >> to perform server side functionality.
        >>
        >> Problem:
        >>
        >> I want to get rid of server control.
        >> Is there a way to perform server side functionality
        >> directly without using server control.
        >>
        >> I tried document.FormNa me.Submit();
        >>
        >> This doesn't work. Is there some other way to do so?
        >>
        >> Thanks & Regards,
        >> -Reetu[/color]
        >.
        >[/color]

        Comment

        Working...