|
-
Jun 7th, 2006, 06:32 AM
#1
Thread Starter
Hyperactive Member
Attributes.Add problem
Hi all,
I have the following code in my HTML document (ASPX page):
VB Code:
function ApplyProposalAccord()
{
if (confirm("Do you wish to apply this proposal?"))
{
document.getElementById('hiddenChoice').value = 1;
document.forms[0].submit;
}
else
{
document.getElementById('hiddenChoice').value = 0;
document.forms[0].submit;
}
}
The button itself is declared this way:
VB Code:
Dim btnApplyProposalDetail As New WebControls.Button
With btnApplyProposalDetail
.ID = "btnApplyProposalDetail"
.Text = "Apply this proposal"
.CausesValidation = False
s = "Are you sure you want to apply this proposal? "
.Attributes.Add("onclick", "ApplyProposalAccord();")
'.Attributes.Add("onclick", "btnApplyProposalDetail_Click();")
'AddHandler btnApplyProposalDetail.Click, AddressOf btnApplyProposalDetail_Click
End With
placeholder1.Controls.Add(New LiteralControl("<tr bgcolor='silver'><td valign=top width=150></td><td>"))
placeholder1.Controls.Add(btnApplyProposalDetail)
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:
Private Sub hiddenChoice_ServerChange(ByVal Sender As System.Object, ByVal e As System.EventArgs) Handles hiddenChoice.ServerChange
If CType(hiddenChoice.Value, Integer) = 1 Then
btnApplyProposalDetail_Click()
Else
'do some other code
'do nothing
End If
End Sub
The code in the first (javascript) code doesn't fire. Does anyone know why?
I'm really disappointed... Thanx in advance...
-
Jun 7th, 2006, 06:41 AM
#2
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)
-
Jun 7th, 2006, 06:53 AM
#3
Thread Starter
Hyperactive Member
Re: Attributes.Add problem
 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:
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?
-
Jun 7th, 2006, 07:03 AM
#4
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?
-
Jun 7th, 2006, 07:16 AM
#5
Thread Starter
Hyperactive Member
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...
-
Jun 7th, 2006, 07:44 AM
#6
Thread Starter
Hyperactive Member
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?
-
Jun 7th, 2006, 07:45 AM
#7
Re: Attributes.Add problem
 Originally Posted by JMvVliet
Hi,
this is the code I get from the source:
VB Code:
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?
-
Jun 7th, 2006, 07:59 AM
#8
Thread Starter
Hyperactive Member
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:
function ApplyProposalAccord()
{
if (confirm("Do you wish to apply this proposal?"))
{
document.getElementById('hiddenChoice').value = 1;
document.forms[0].submit;
}
else
{
document.getElementById('hiddenChoice').value = 0;
document.forms[0].submit;
}
}
hiddenChoice is a variable inside the ASPX page:
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|