Injecting javascript into a particular part in a page from inside a codebehind file.

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

    Injecting javascript into a particular part in a page from inside a codebehind file.

    How do you add javascript to a page from codebehind? I have a method I am
    working on that has a few conditions in it:

    1. if either 1 or both WordTextBox or DefinitionTextB ox is empty, show a
    popup window telling the user that the textbox(s) can't be empty and return
    them to the page with no further action.
    2. The value in WordTextBox is already in the collection as a key, so show a
    popup telling the user that the word already exists and then return them to
    the page with no further action.

    How would you do this?



  • Alexey Smirnov

    #2
    Re: Injecting javascript into a particular part in a page from insidea codebehind file.

    On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglo bal.netwrote:
    How do you add javascript to a page from codebehind? I have a method I am
    working on that has a few conditions in it:
    >
    1. if either 1 or both WordTextBox or DefinitionTextB ox is empty, show a
    popup window telling the user that the textbox(s) can't be empty and return
    them to the page with no further action.
    2. The value in WordTextBox is already in the collection as a key, so showa
    popup telling the user that the word already exists and then return them to
    the page with no further action.
    >
    How would you do this?
    1. I think you can do this with ASP.NET RequiredFieldVa lidator &
    ValidationSumma ry Controls
    2. How do you get collection? Is it a database value?

    Comment

    • Andy B

      #3
      Re: Injecting javascript into a particular part in a page from inside a codebehind file.

      collection is a dictionary<stri n, string>

      "Alexey Smirnov" <alexey.smirnov @gmail.comwrote in message
      news:a5d35bba-47a1-4c68-a62f-3ad5a8098148@s5 0g2000hsb.googl egroups.com...
      On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglo bal.netwrote:
      How do you add javascript to a page from codebehind? I have a method I am
      working on that has a few conditions in it:
      >
      1. if either 1 or both WordTextBox or DefinitionTextB ox is empty, show a
      popup window telling the user that the textbox(s) can't be empty and
      return
      them to the page with no further action.
      2. The value in WordTextBox is already in the collection as a key, so show
      a
      popup telling the user that the word already exists and then return them
      to
      the page with no further action.
      >
      How would you do this?
      1. I think you can do this with ASP.NET RequiredFieldVa lidator &
      ValidationSumma ry Controls
      2. How do you get collection? Is it a database value?


      Comment

      • clintonG

        #4
        Re: Injecting javascript into a particular part in a page from inside a codebehind file.

        /*
        How to validate two textboxes to ensure only one textbox contains data. Copy
        and paste into Visual Studio for best results reading and comprehending how
        this solution may be helpful to learn from...

        */

        <%-- CUSTOM VALIDATOR --%>
        <asp:CustomVali dator
        ID="ManagingEdi torValidator" runat="server"
        EnableViewState ="false"
        OnServerValidat e="ManagingEdit orTextBoxes_Cus tomValidator"
        ErrorMessage="" />


        // CustomValidator raises this event...
        #region Validation: ManagingEditorT extBoxes_Custom Validator...
        protected void ManagingEditorT extBoxes_Custom Validator(objec t
        source, ServerValidateE ventArgs args)
        {
        if (ChannelManagin gEditorEmailTex tBox.Text.Lengt h 0 &&
        ChannelManaging EditorNameTextB ox.Text.Length 0)
        {
        args.IsValid = false;
        ManagingEditorV alidationLabel. Text = "<span
        style='color:re d;font-weight:bold;'>O nly one TextBox may contain
        data.</span>";
        ChannelBuilderW izard.ActiveSte pIndex = 5; //
        Step5_ChannelMa nagingEditor
        }
        else
        {
        args.IsValid = true;
        ManagingEditorV alidationLabel. Text = "-- or --";
        }
        }//protected void ManagingEditorT extBoxes_Custom Validator(objec t
        source, ServerValidateE ventArgs args)
        #endregion

        /*
        I also used the OnActiveStepCha nged event of a Wizard control to determine
        when to call a ValidateManagin gEditorOrWebmas terTextBoxes() method
        that --also-- modifies the ManagingEditorV alidationLabel I have mentioned.
        You can figure out where to call the method once you study and learn how
        this example of server-side validation works.
        */


        #region Validation: ValidateManagin gEditorOrWebmas terTextBoxes...
        // Both ManagingEditor and Webmaster steps display a set of
        TextBoxes; one for email and another for a name
        // but only one TextBox may be used to submit data.
        // ChannelBuilderW izard_OnActiveS tepChanged calls this method when
        selecting the Wizard's Next button.
        // ManagingEditorT extBoxes_Custom Validator and
        WebmasterTextBo xes_CustomValid ator are called when SideBar LinkButtons are
        selected.
        protected void ValidateManagin gEditorOrWebmas terTextBoxes()
        {
        if (ChannelManagin gEditorEmailTex tBox.Text.Lengt h 0 &&
        ChannelManaging EditorNameTextB ox.Text.Length 0)
        {
        ManagingEditorV alidationLabel. Text = "<span
        style='color:re d;font-weight:bold;'>O nly one TextBox may contain
        data.</span>";
        ChannelBuilderW izard.ActiveSte pIndex = 5;
        }
        else if (ChannelWebmast erEmailTextBox. Text.Length 0 &&
        ChannelWebmaste rNameTextBox.Te xt.Length 0)
        {
        WebmasterValida tionLabel.Text = "<span
        style='color:re d;font-weight:bold;'>O nly one TextBox may contain
        data.</span>";
        ChannelBuilderW izard.ActiveSte pIndex = 6;
        }
        else
        {
        if
        (String.IsNullO rEmpty(ChannelM anagingEditorEm ailTextBox.Text .ToString()) ||
        String.IsNullOr Empty(ChannelMa nagingEditorNam eTextBox.Text.T oString()))
        {
        ManagingEditorV alidationLabel. Text = "-- or --";
        }
        if
        (String.IsNullO rEmpty(ChannelW ebmasterEmailTe xtBox.Text.ToSt ring()) ||
        String.IsNullOr Empty(ChannelWe bmasterNameText Box.Text.ToStri ng()))
        {
        WebmasterValida tionLabel.Text = "-- or --";
        }
        }
        }//ValidateManagin gEditorAndWebma sterTextBoxes()
        #endregion

        <%= Clinton Gallagher


        "Andy B" <a_borka@sbcglo bal.netwrote in message
        news:%237NJOtwp IHA.1240@TK2MSF TNGP02.phx.gbl. ..
        collection is a dictionary<stri n, string>
        >
        "Alexey Smirnov" <alexey.smirnov @gmail.comwrote in message
        news:a5d35bba-47a1-4c68-a62f-3ad5a8098148@s5 0g2000hsb.googl egroups.com...
        On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglo bal.netwrote:
        >How do you add javascript to a page from codebehind? I have a method I am
        >working on that has a few conditions in it:
        >>
        >1. if either 1 or both WordTextBox or DefinitionTextB ox is empty, show a
        >popup window telling the user that the textbox(s) can't be empty and
        >return
        >them to the page with no further action.
        >2. The value in WordTextBox is already in the collection as a key, so
        >show a
        >popup telling the user that the word already exists and then return them
        >to
        >the page with no further action.
        >>
        >How would you do this?
        >
        1. I think you can do this with ASP.NET RequiredFieldVa lidator &
        ValidationSumma ry Controls
        2. How do you get collection? Is it a database value?
        >

        Comment

        • Andy B

          #5
          Re: Injecting javascript into a particular part in a page from inside a codebehind file.

          This wasn't exactly what I was looking for. I need to have a popup window
          (the javascript alert window) pop up if:

          1. The WordTextBox.Tex t property is empty.
          2. The DefinitionTextB ox.Text property is empty.
          3. Both WordTextBox.Tex t and DefinitionTextB ox.Text are empty at the same
          time.
          4. The value for WordTextBox.Tex t already exists inside the dictionary
          collection.

          Of course all of these have different messages that go along with them.


          "clintonG" <nobody@nowhere .comwrote in message
          news:Oos7UkzpIH A.2636@TK2MSFTN GP04.phx.gbl...
          /*
          How to validate two textboxes to ensure only one textbox contains data.
          Copy and paste into Visual Studio for best results reading and
          comprehending how this solution may be helpful to learn from...
          >
          */
          >
          <%-- CUSTOM VALIDATOR --%>
          <asp:CustomVali dator
          ID="ManagingEdi torValidator" runat="server"
          EnableViewState ="false"
          OnServerValidat e="ManagingEdit orTextBoxes_Cus tomValidator"
          ErrorMessage="" />
          >
          >
          // CustomValidator raises this event...
          #region Validation: ManagingEditorT extBoxes_Custom Validator...
          protected void ManagingEditorT extBoxes_Custom Validator(objec t
          source, ServerValidateE ventArgs args)
          {
          if (ChannelManagin gEditorEmailTex tBox.Text.Lengt h 0 &&
          ChannelManaging EditorNameTextB ox.Text.Length 0)
          {
          args.IsValid = false;
          ManagingEditorV alidationLabel. Text = "<span
          style='color:re d;font-weight:bold;'>O nly one TextBox may contain
          data.</span>";
          ChannelBuilderW izard.ActiveSte pIndex = 5; //
          Step5_ChannelMa nagingEditor
          }
          else
          {
          args.IsValid = true;
          ManagingEditorV alidationLabel. Text = "-- or --";
          }
          }//protected void ManagingEditorT extBoxes_Custom Validator(objec t
          source, ServerValidateE ventArgs args)
          #endregion
          >
          /*
          I also used the OnActiveStepCha nged event of a Wizard control to determine
          when to call a ValidateManagin gEditorOrWebmas terTextBoxes() method
          that --also-- modifies the ManagingEditorV alidationLabel I have mentioned.
          You can figure out where to call the method once you study and learn how
          this example of server-side validation works.
          */
          >
          >
          #region Validation: ValidateManagin gEditorOrWebmas terTextBoxes...
          // Both ManagingEditor and Webmaster steps display a set of
          TextBoxes; one for email and another for a name
          // but only one TextBox may be used to submit data.
          // ChannelBuilderW izard_OnActiveS tepChanged calls this method when
          selecting the Wizard's Next button.
          // ManagingEditorT extBoxes_Custom Validator and
          WebmasterTextBo xes_CustomValid ator are called when SideBar LinkButtons are
          selected.
          protected void ValidateManagin gEditorOrWebmas terTextBoxes()
          {
          if (ChannelManagin gEditorEmailTex tBox.Text.Lengt h 0 &&
          ChannelManaging EditorNameTextB ox.Text.Length 0)
          {
          ManagingEditorV alidationLabel. Text = "<span
          style='color:re d;font-weight:bold;'>O nly one TextBox may contain
          data.</span>";
          ChannelBuilderW izard.ActiveSte pIndex = 5;
          }
          else if (ChannelWebmast erEmailTextBox. Text.Length 0 &&
          ChannelWebmaste rNameTextBox.Te xt.Length 0)
          {
          WebmasterValida tionLabel.Text = "<span
          style='color:re d;font-weight:bold;'>O nly one TextBox may contain
          data.</span>";
          ChannelBuilderW izard.ActiveSte pIndex = 6;
          }
          else
          {
          if
          (String.IsNullO rEmpty(ChannelM anagingEditorEm ailTextBox.Text .ToString())
          || String.IsNullOr Empty(ChannelMa nagingEditorNam eTextBox.Text.T oString()))
          {
          ManagingEditorV alidationLabel. Text = "-- or --";
          }
          if
          (String.IsNullO rEmpty(ChannelW ebmasterEmailTe xtBox.Text.ToSt ring()) ||
          String.IsNullOr Empty(ChannelWe bmasterNameText Box.Text.ToStri ng()))
          {
          WebmasterValida tionLabel.Text = "-- or --";
          }
          }
          }//ValidateManagin gEditorAndWebma sterTextBoxes()
          #endregion
          >
          <%= Clinton Gallagher
          >
          >
          "Andy B" <a_borka@sbcglo bal.netwrote in message
          news:%237NJOtwp IHA.1240@TK2MSF TNGP02.phx.gbl. ..
          >collection is a dictionary<stri n, string>
          >>
          >"Alexey Smirnov" <alexey.smirnov @gmail.comwrote in message
          >news:a5d35bb a-47a1-4c68-a62f-3ad5a8098148@s5 0g2000hsb.googl egroups.com...
          >On Apr 25, 7:19 pm, "Andy B" <a_bo...@sbcglo bal.netwrote:
          >>How do you add javascript to a page from codebehind? I have a method I
          >>am
          >>working on that has a few conditions in it:
          >>>
          >>1. if either 1 or both WordTextBox or DefinitionTextB ox is empty, show a
          >>popup window telling the user that the textbox(s) can't be empty and
          >>return
          >>them to the page with no further action.
          >>2. The value in WordTextBox is already in the collection as a key, so
          >>show a
          >>popup telling the user that the word already exists and then return them
          >>to
          >>the page with no further action.
          >>>
          >>How would you do this?
          >>
          >1. I think you can do this with ASP.NET RequiredFieldVa lidator &
          >ValidationSumm ary Controls
          >2. How do you get collection? Is it a database value?
          >>
          >

          Comment

          Working...