Results 1 to 8 of 8

Thread: Attributes.Add problem

  1. #1

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Unhappy Attributes.Add problem

    Hi all,

    I have the following code in my HTML document (ASPX page):
    VB Code:
    1. function ApplyProposalAccord()
    2.     {
    3.     if (confirm("Do you wish to apply this proposal?"))
    4.     {
    5.     document.getElementById('hiddenChoice').value = 1;
    6.     document.forms[0].submit;
    7.     }
    8.     else
    9.     {
    10.     document.getElementById('hiddenChoice').value = 0;
    11.     document.forms[0].submit;
    12.     }
    13. }

    The button itself is declared this way:
    VB Code:
    1. Dim btnApplyProposalDetail As New WebControls.Button
    2.                     With btnApplyProposalDetail
    3.                         .ID = "btnApplyProposalDetail"
    4.                         .Text = "Apply this proposal"
    5.                         .CausesValidation = False
    6.                         s = "Are you sure you want to apply this proposal? "
    7.                         .Attributes.Add("onclick", "ApplyProposalAccord();")
    8.                         '.Attributes.Add("onclick", "btnApplyProposalDetail_Click();")
    9.                         'AddHandler btnApplyProposalDetail.Click, AddressOf btnApplyProposalDetail_Click
    10.                     End With
    11.                     placeholder1.Controls.Add(New LiteralControl("<tr bgcolor='silver'><td valign=top width=150></td><td>"))
    12.                     placeholder1.Controls.Add(btnApplyProposalDetail)
    13.                     placeholder1.Controls.Add(New LiteralControl("</td><tr>"))

    In my ASPX page, the 'hiddenChoice' value is typed WithEvents System.Web.UI.HtmlControls.HtmlInputHidden. If I click on the button, the following code should be executed, but it doesn't:

    VB Code:
    1. Private Sub hiddenChoice_ServerChange(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles hiddenChoice.ServerChange
    2.         If CType(hiddenChoice.Value, Integer) = 1 Then
    3.             btnApplyProposalDetail_Click()
    4.         Else
    5.             'do some other code
    6.             'do nothing
    7.         End If
    8.     End Sub

    The code in the first (javascript) code doesn't fire. Does anyone know why?

    I'm really disappointed... Thanx in advance...

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Attributes.Add problem

    Look at the source code of the html that is displayed in the browser. Is the ID attribute of the hidden field exactly 'hiddenChoice' or is it something else? (ASP.NET does change some IDs)

  3. #3

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: Attributes.Add problem

    Quote Originally Posted by mendhak
    Look at the source code of the html that is displayed in the browser. Is the ID attribute of the hidden field exactly 'hiddenChoice' or is it something else? (ASP.NET does change some IDs)
    Hi,

    this is the code I get from the source:
    VB Code:
    1. input type="submit" name="btnApplyProposalDetail" value="Apply this proposal" id="btnApplyProposalDetail" onclick="ApplyProposalAccord();" />
    The javascript function itself isn't found in the HTML when I search for it... Could that be the problem?

  4. #4
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Attributes.Add problem

    Yes that will be a problem. Your first post said that it was in the .aspx page, so where did it go?

  5. #5

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: Attributes.Add problem

    Ok, I've found out is was hidden in a conditional IF statement (<%if somevariable=true and so on)...

    Now, it asks me to apply as I want, it only doesn't fire the ASP.NET code...

    I'm further than I've been... Thanx for the help so far, maybe u could help me with the last part...

  6. #6

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: Attributes.Add problem

    Have replaced the Webcontrols.Button by a HTMLButton. Now I get the error: document.getElementById( is null or not an object. Anyone knows how that could happen?

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Attributes.Add problem

    Quote Originally Posted by JMvVliet
    Hi,

    this is the code I get from the source:
    VB Code:
    1. input type="submit" name="btnApplyProposalDetail" value="Apply this proposal" id="btnApplyProposalDetail" onclick="ApplyProposalAccord();" />
    The javascript function itself isn't found in the HTML when I search for it... Could that be the problem?
    That isn't the hidden field.

    Also, how are you adding the javascript function to the page?

  8. #8

    Thread Starter
    Hyperactive Member JMvVliet's Avatar
    Join Date
    May 2001
    Location
    Papendrecht, Netherlands
    Posts
    310

    Re: Attributes.Add problem

    The ApplyProposalAccord is inserted into the HTML part of the page. See the first post how I add the 'onclick' event to the attributes, calling ApplyProposalAccord.

    ApplyProposalAccord:
    VB Code:
    1. function ApplyProposalAccord()
    2.     {
    3.     if (confirm("Do you wish to apply this proposal?"))
    4.     {
    5.     document.getElementById('hiddenChoice').value = 1;
    6.     document.forms[0].submit;
    7.     }
    8.     else
    9.     {
    10.     document.getElementById('hiddenChoice').value = 0;
    11.     document.forms[0].submit;
    12.     }
    13. }

    hiddenChoice is a variable inside the ASPX page:
    VB Code:
    1. Protected hiddenChoice As System.Web.UI.HtmlControls.HtmlInputHidden

    Before finding out how to fire the events of this control (I need a WithEvents therefore, I think), I want to figure out why I get the error mentioned in my post before...

    I am getting the message that asks me if I want to apply the proposal. But after clicking OK, the I get the mentioned message.

    Thanx anyway...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width