A dynamically added button makes post back to login page
In order to Add dynamically a Button I use the following code inside the LoginButton_Click
sub
Dim ModeratorButton As New Button
AddHandler ModeratorButton.Click,
AddressOf Me.ModeratorButton_Click
With ModeratorButton
.ID = "ModeratorButton"
.Attributes("OnClientClick") = "ModeratorButton_Click"
.CssClass = "ModeratorButton"
.Text = "Ενημέρωση"
End With
MessagesPanel.Controls.Add(ModeratorButton)
I also have a protected sub in order to handle the event
Private Sub ModeratorButton_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
As a result of all these I receive the normal page
With the Panel I want and the controls I need in it.
The issue starts when I push the ModeratorButton
and the code never goes to the protected sub
I mention earlier
Instead of that it makes a post back to the LoginPage
Is someone to assist me on this?
vb.net onclicklistener buttonclick
add a comment |
In order to Add dynamically a Button I use the following code inside the LoginButton_Click
sub
Dim ModeratorButton As New Button
AddHandler ModeratorButton.Click,
AddressOf Me.ModeratorButton_Click
With ModeratorButton
.ID = "ModeratorButton"
.Attributes("OnClientClick") = "ModeratorButton_Click"
.CssClass = "ModeratorButton"
.Text = "Ενημέρωση"
End With
MessagesPanel.Controls.Add(ModeratorButton)
I also have a protected sub in order to handle the event
Private Sub ModeratorButton_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
As a result of all these I receive the normal page
With the Panel I want and the controls I need in it.
The issue starts when I push the ModeratorButton
and the code never goes to the protected sub
I mention earlier
Instead of that it makes a post back to the LoginPage
Is someone to assist me on this?
vb.net onclicklistener buttonclick
What are the statements under theModeratorButton_Click
event. And in theAddHandler
, useAddHandler ModeratorButton.Click, AddressOf ModeratorButton_Click
– preciousbetine
Nov 20 '18 at 2:46
@preciousbetine With the AddHandler I'm adding the event handler for the button.click.
– Lefteris Gkinis
Nov 20 '18 at 20:05
add a comment |
In order to Add dynamically a Button I use the following code inside the LoginButton_Click
sub
Dim ModeratorButton As New Button
AddHandler ModeratorButton.Click,
AddressOf Me.ModeratorButton_Click
With ModeratorButton
.ID = "ModeratorButton"
.Attributes("OnClientClick") = "ModeratorButton_Click"
.CssClass = "ModeratorButton"
.Text = "Ενημέρωση"
End With
MessagesPanel.Controls.Add(ModeratorButton)
I also have a protected sub in order to handle the event
Private Sub ModeratorButton_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
As a result of all these I receive the normal page
With the Panel I want and the controls I need in it.
The issue starts when I push the ModeratorButton
and the code never goes to the protected sub
I mention earlier
Instead of that it makes a post back to the LoginPage
Is someone to assist me on this?
vb.net onclicklistener buttonclick
In order to Add dynamically a Button I use the following code inside the LoginButton_Click
sub
Dim ModeratorButton As New Button
AddHandler ModeratorButton.Click,
AddressOf Me.ModeratorButton_Click
With ModeratorButton
.ID = "ModeratorButton"
.Attributes("OnClientClick") = "ModeratorButton_Click"
.CssClass = "ModeratorButton"
.Text = "Ενημέρωση"
End With
MessagesPanel.Controls.Add(ModeratorButton)
I also have a protected sub in order to handle the event
Private Sub ModeratorButton_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
As a result of all these I receive the normal page
With the Panel I want and the controls I need in it.
The issue starts when I push the ModeratorButton
and the code never goes to the protected sub
I mention earlier
Instead of that it makes a post back to the LoginPage
Is someone to assist me on this?
vb.net onclicklistener buttonclick
vb.net onclicklistener buttonclick
edited Nov 19 '18 at 22:34
Lefteris Gkinis
asked Nov 19 '18 at 20:00
Lefteris GkinisLefteris Gkinis
63042153
63042153
What are the statements under theModeratorButton_Click
event. And in theAddHandler
, useAddHandler ModeratorButton.Click, AddressOf ModeratorButton_Click
– preciousbetine
Nov 20 '18 at 2:46
@preciousbetine With the AddHandler I'm adding the event handler for the button.click.
– Lefteris Gkinis
Nov 20 '18 at 20:05
add a comment |
What are the statements under theModeratorButton_Click
event. And in theAddHandler
, useAddHandler ModeratorButton.Click, AddressOf ModeratorButton_Click
– preciousbetine
Nov 20 '18 at 2:46
@preciousbetine With the AddHandler I'm adding the event handler for the button.click.
– Lefteris Gkinis
Nov 20 '18 at 20:05
What are the statements under the
ModeratorButton_Click
event. And in the AddHandler
, use AddHandler ModeratorButton.Click, AddressOf ModeratorButton_Click
– preciousbetine
Nov 20 '18 at 2:46
What are the statements under the
ModeratorButton_Click
event. And in the AddHandler
, use AddHandler ModeratorButton.Click, AddressOf ModeratorButton_Click
– preciousbetine
Nov 20 '18 at 2:46
@preciousbetine With the AddHandler I'm adding the event handler for the button.click.
– Lefteris Gkinis
Nov 20 '18 at 20:05
@preciousbetine With the AddHandler I'm adding the event handler for the button.click.
– Lefteris Gkinis
Nov 20 '18 at 20:05
add a comment |
1 Answer
1
active
oldest
votes
After postback you need to AddHandler again.
For example, like this.
Private Sub _Default_Load(sender As Object, e As EventArgs) Handles Me.Load
If Request.Form("LoginButton") IsNot Nothing Or
Request.Form("ModeratorButton") IsNot Nothing Then
Dim ModeratorButton As New Button
With ModeratorButton
.ID = "ModeratorButton"
.Attributes("OnClientClick") = "ModeratorButton_Click"
.CssClass = "ModeratorButton"
.Text = "Ενημέρωση"
End With
AddHandler ModeratorButton.Click, AddressOf Me.ModeratorButton_Click
MessagesPanel.Controls.Add(ModeratorButton)
End If
End Sub
Private Sub ModeratorButton_Click(sender As Object, e As EventArgs)
End Sub
https://support.microsoft.com/en-us/help/317794/how-to-dynamically-create-controls-in-asp-net-by-using-visual-c-net
Note When you create dynamic controls on a Web Form, the controls must be created and added to the controls collection either in the OnInit or in the Page_Load events. Otherwise, the controls behave unexpectedly.
@m.mukai Yes... that was the solution. Call them on thpage_Load
sub and raise them when ever you want.... yes that's it Thank you very much
– Lefteris Gkinis
Nov 20 '18 at 20:08
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381796%2fa-dynamically-added-button-makes-post-back-to-login-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After postback you need to AddHandler again.
For example, like this.
Private Sub _Default_Load(sender As Object, e As EventArgs) Handles Me.Load
If Request.Form("LoginButton") IsNot Nothing Or
Request.Form("ModeratorButton") IsNot Nothing Then
Dim ModeratorButton As New Button
With ModeratorButton
.ID = "ModeratorButton"
.Attributes("OnClientClick") = "ModeratorButton_Click"
.CssClass = "ModeratorButton"
.Text = "Ενημέρωση"
End With
AddHandler ModeratorButton.Click, AddressOf Me.ModeratorButton_Click
MessagesPanel.Controls.Add(ModeratorButton)
End If
End Sub
Private Sub ModeratorButton_Click(sender As Object, e As EventArgs)
End Sub
https://support.microsoft.com/en-us/help/317794/how-to-dynamically-create-controls-in-asp-net-by-using-visual-c-net
Note When you create dynamic controls on a Web Form, the controls must be created and added to the controls collection either in the OnInit or in the Page_Load events. Otherwise, the controls behave unexpectedly.
@m.mukai Yes... that was the solution. Call them on thpage_Load
sub and raise them when ever you want.... yes that's it Thank you very much
– Lefteris Gkinis
Nov 20 '18 at 20:08
add a comment |
After postback you need to AddHandler again.
For example, like this.
Private Sub _Default_Load(sender As Object, e As EventArgs) Handles Me.Load
If Request.Form("LoginButton") IsNot Nothing Or
Request.Form("ModeratorButton") IsNot Nothing Then
Dim ModeratorButton As New Button
With ModeratorButton
.ID = "ModeratorButton"
.Attributes("OnClientClick") = "ModeratorButton_Click"
.CssClass = "ModeratorButton"
.Text = "Ενημέρωση"
End With
AddHandler ModeratorButton.Click, AddressOf Me.ModeratorButton_Click
MessagesPanel.Controls.Add(ModeratorButton)
End If
End Sub
Private Sub ModeratorButton_Click(sender As Object, e As EventArgs)
End Sub
https://support.microsoft.com/en-us/help/317794/how-to-dynamically-create-controls-in-asp-net-by-using-visual-c-net
Note When you create dynamic controls on a Web Form, the controls must be created and added to the controls collection either in the OnInit or in the Page_Load events. Otherwise, the controls behave unexpectedly.
@m.mukai Yes... that was the solution. Call them on thpage_Load
sub and raise them when ever you want.... yes that's it Thank you very much
– Lefteris Gkinis
Nov 20 '18 at 20:08
add a comment |
After postback you need to AddHandler again.
For example, like this.
Private Sub _Default_Load(sender As Object, e As EventArgs) Handles Me.Load
If Request.Form("LoginButton") IsNot Nothing Or
Request.Form("ModeratorButton") IsNot Nothing Then
Dim ModeratorButton As New Button
With ModeratorButton
.ID = "ModeratorButton"
.Attributes("OnClientClick") = "ModeratorButton_Click"
.CssClass = "ModeratorButton"
.Text = "Ενημέρωση"
End With
AddHandler ModeratorButton.Click, AddressOf Me.ModeratorButton_Click
MessagesPanel.Controls.Add(ModeratorButton)
End If
End Sub
Private Sub ModeratorButton_Click(sender As Object, e As EventArgs)
End Sub
https://support.microsoft.com/en-us/help/317794/how-to-dynamically-create-controls-in-asp-net-by-using-visual-c-net
Note When you create dynamic controls on a Web Form, the controls must be created and added to the controls collection either in the OnInit or in the Page_Load events. Otherwise, the controls behave unexpectedly.
After postback you need to AddHandler again.
For example, like this.
Private Sub _Default_Load(sender As Object, e As EventArgs) Handles Me.Load
If Request.Form("LoginButton") IsNot Nothing Or
Request.Form("ModeratorButton") IsNot Nothing Then
Dim ModeratorButton As New Button
With ModeratorButton
.ID = "ModeratorButton"
.Attributes("OnClientClick") = "ModeratorButton_Click"
.CssClass = "ModeratorButton"
.Text = "Ενημέρωση"
End With
AddHandler ModeratorButton.Click, AddressOf Me.ModeratorButton_Click
MessagesPanel.Controls.Add(ModeratorButton)
End If
End Sub
Private Sub ModeratorButton_Click(sender As Object, e As EventArgs)
End Sub
https://support.microsoft.com/en-us/help/317794/how-to-dynamically-create-controls-in-asp-net-by-using-visual-c-net
Note When you create dynamic controls on a Web Form, the controls must be created and added to the controls collection either in the OnInit or in the Page_Load events. Otherwise, the controls behave unexpectedly.
edited Nov 20 '18 at 7:45
answered Nov 20 '18 at 7:28
m mukaim mukai
1916
1916
@m.mukai Yes... that was the solution. Call them on thpage_Load
sub and raise them when ever you want.... yes that's it Thank you very much
– Lefteris Gkinis
Nov 20 '18 at 20:08
add a comment |
@m.mukai Yes... that was the solution. Call them on thpage_Load
sub and raise them when ever you want.... yes that's it Thank you very much
– Lefteris Gkinis
Nov 20 '18 at 20:08
@m.mukai Yes... that was the solution. Call them on th
page_Load
sub and raise them when ever you want.... yes that's it Thank you very much– Lefteris Gkinis
Nov 20 '18 at 20:08
@m.mukai Yes... that was the solution. Call them on th
page_Load
sub and raise them when ever you want.... yes that's it Thank you very much– Lefteris Gkinis
Nov 20 '18 at 20:08
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53381796%2fa-dynamically-added-button-makes-post-back-to-login-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What are the statements under the
ModeratorButton_Click
event. And in theAddHandler
, useAddHandler ModeratorButton.Click, AddressOf ModeratorButton_Click
– preciousbetine
Nov 20 '18 at 2:46
@preciousbetine With the AddHandler I'm adding the event handler for the button.click.
– Lefteris Gkinis
Nov 20 '18 at 20:05