Showing posts with label events. Show all posts
Showing posts with label events. Show all posts

Thursday, March 29, 2012

Off-Page Rendering of Server Controls with events

Hey everyone. I have another problem. I have an aspx web page that
contains an event. When the event is fired it creates an instance of a
server control that contains an event of its own. I would like to be
able to render the contents of the server control (HTML w/ event
JavaScript code) and store it for later use.

My problem lies when I call the MyControl.RenderControl method. It
returns valid HTML but does not contain the event code since the
control has not been added to any page object.

Here is what I have tried:

HtmlForm hForm = new System.Web.UI.HtmlControls.HtmlForm();
hForm.Attributes.Add("runat", "server");
hForm.Controls.Add(spWC);

Page p = new Page();
p.Controls.Add(hForm);
p.RenderControl(hWriter); // <-- error here stating that no Response
object available.

I do understand that I am getting a "Response not available" error
because there is no context associated with the newly created page
object. Any ideas as to how I can achieve the results I am looking
for?

-DavidOn Feb 21, 9:15 am, "Bob Jones" <goodold...@.gmail.comwrote:

Quote:

Originally Posted by

Hey everyone. I have another problem. I have an aspx web page that
contains an event. When the event is fired it creates an instance of a
server control that contains an event of its own. I would like to be
able to render the contents of the server control (HTML w/ event
JavaScript code) and store it for later use.
>
My problem lies when I call the MyControl.RenderControl method. It
returns valid HTML but does not contain the event code since the
control has not been added to any page object.
>
Here is what I have tried:
>
HtmlForm hForm = new System.Web.UI.HtmlControls.HtmlForm();
hForm.Attributes.Add("runat", "server");
hForm.Controls.Add(spWC);
>
Page p = new Page();
p.Controls.Add(hForm);
p.RenderControl(hWriter); // <-- error here stating that no Response
object available.
>
I do understand that I am getting a "Response not available" error
because there is no context associated with the newly created page
object. Any ideas as to how I can achieve the results I am looking
for?
>
-David


sp, nobody on here has any idea on how to get this working? Or if it's
even possible

Off-Page Rendering of Server Controls with events

Hey everyone. I have another problem. I have an aspx web page that
contains an event. When the event is fired it creates an instance of a
server control that contains an event of its own. I would like to be
able to render the contents of the server control (HTML w/ event
JavaScript code) and store it for later use.
My problem lies when I call the MyControl.RenderControl method. It
returns valid HTML but does not contain the event code since the
control has not been added to any page object.
Here is what I have tried:
HtmlForm hForm = new System.Web.UI.HtmlControls.HtmlForm();
hForm.Attributes.Add("runat", "server");
hForm.Controls.Add(spWC);
Page p = new Page();
p.Controls.Add(hForm);
p.RenderControl(hWriter); // <-- error here stating that no Response
object available.
I do understand that I am getting a "Response not available" error
because there is no context associated with the newly created page
object. Any ideas as to how I can achieve the results I am looking
for?
-DavidOn Feb 21, 9:15 am, "Bob Jones" <goodold...@.gmail.com> wrote:
> Hey everyone. I have another problem. I have an aspx web page that
> contains an event. When the event is fired it creates an instance of a
> server control that contains an event of its own. I would like to be
> able to render the contents of the server control (HTML w/ event
> JavaScript code) and store it for later use.
> My problem lies when I call the MyControl.RenderControl method. It
> returns valid HTML but does not contain the event code since the
> control has not been added to any page object.
> Here is what I have tried:
> HtmlForm hForm = new System.Web.UI.HtmlControls.HtmlForm();
> hForm.Attributes.Add("runat", "server");
> hForm.Controls.Add(spWC);
> Page p = new Page();
> p.Controls.Add(hForm);
> p.RenderControl(hWriter); // <-- error here stating that no Response
> object available.
> I do understand that I am getting a "Response not available" error
> because there is no context associated with the newly created page
> object. Any ideas as to how I can achieve the results I am looking
> for?
> -David
sp, nobody on here has any idea on how to get this working? Or if it's
even possible

Saturday, March 24, 2012

Old Age Problem: Refresh Button Causes Postback

This is an old problem,, but I never had it so bad like this before,,
the events are refiring when clicking the Browser refresh button.
In the Submit button in my webform, I capture the server side click
event and I update session information to track the visibilty of some
panels in a wizard type navigation ("Next >>" and "<< Back" buttons)..
but the refresh button makes another event firing and takes the whole
thing to a Choes..

redirection to the same page/ saving state in a database is dumb and
should not be mentioned as an answer .. and Please, don't reply if you
are guessing.

thanks.This is more ranting and less of an explanation of what is happening and
what your problem really is...

When you hit refresh, you are not causing a postback. You are causing the
page class to be re-created and therefore, its New, Init, LoadViewState,
Page_Load , SaveViewState, control events and unload events are fired in
sequence. This is because of the stateless nature of the web, not ASP.NET.

PostBack occurs when form data is submitted. A refresh does not always
accomplish this.

What exactly is the problem you are experiencing. Pardon me if this sounds
sarcastic (it really isn't meant that way), but it's been my experience that
a better understanding of the Page class's lifecycle serves to eliminate
questions regarding postback.

"tasmisr" <tasmisr@.hotmail.com> wrote in message
news:ff5c43f8.0312221819.7f400a09@.posting.google.c om...
> This is an old problem,, but I never had it so bad like this before,,
> the events are refiring when clicking the Browser refresh button.
> In the Submit button in my webform, I capture the server side click
> event and I update session information to track the visibilty of some
> panels in a wizard type navigation ("Next >>" and "<< Back" buttons)..
> but the refresh button makes another event firing and takes the whole
> thing to a Choes..
> redirection to the same page/ saving state in a database is dumb and
> should not be mentioned as an answer .. and Please, don't reply if you
> are guessing.
> thanks.
I know you are trying to help.
I fully understand the life cycle of the page object but I would
recommend that you step through the debugger and click the refresh
button and see what happens, the refresh button resubmits the data to
the server exactly the same as submitting the form for the first time.
Please I'm sick of submitting to these newsgroups and getting
nonhelpful answers, SO DON'T ANSWER IF YOU DON'T KNOW!
And here is the answer, to use a ViewState to retain the info instead
of the Session object.
Wow, you make me want to spend some time on your problem and help you out!

I stated in my last message: "PostBack occurs when form data is submitted.
A refresh does not always
accomplish this." This is true. If no data was submitted prior to the
refresh, then there is no data to repost. I said this in my first message
but you only tested it under one particular circumstance.

Are you sure you didn't write your "answer" backwards? Did you mean use
Session instead of ViewState? This would get around your re-posting problem
(since ViewState is on by default), but you now have to be very careful
since the session can be disabled by the client (session cookies) and the
server. Even if sessions are not disabled, they do take up overhead on the
server and if you are expecting any kind of significant volumne for the
page, they may not be the best solution.

Lastly, a word or 2 for you...I posted a reply to you and mentioned that
your post was not clear and that you needed to be more specific about what
problem you were having. You response was: "Please I'm sick of submitting
to these newsgroups and getting nonhelpful answers, SO DON'T ANSWER IF YOU
DON'T KNOW!"

So I guess I have this to say, "Please, I'm sick of reading posts that
aren't clear about what the problem is and are nothing more that venting
frustration at the rest of us, SO DON'T POST QUESTION IF YOU DON'T EXPLAIN
WHAT THE PROBLEM IS!"

"tasmisr" <tasmisr@.hotmail.com> wrote in message
news:ff5c43f8.0312230718.4913d6a6@.posting.google.c om...
> And here is the answer, to use a ViewState to retain the info instead
> of the Session object.
tasmisr@.hotmail.com (tasmisr) wrote in message news:<ff5c43f8.0312230707.d637b1d@.posting.google.com>...
> Please I'm sick of submitting to these newsgroups and getting
> nonhelpful answers, SO DON'T ANSWER IF YOU DON'T KNOW!

Hey, pal, chill out! Nobody OWES you anything here. People are posting
mostly out of the goodness of their hearts. If you are "sick" of it,
no one is forcing you to post! There are alternatives you know--here
are a few: post to a different group, don't post at all, call MS tech
support, buy a book on ASP.NET (and read it), read the MSDN help
files, hire someone else to do your job, don't do development in this
technology, get out of software development altogether... A quick
Google Groups search of the posts made from your email address shows
that people have been helpful to you more often than not.
>>People are posting mostly out of the goodness of their >>hearts.

I guess not, some people are not, they just don't understand the
technology and they are posting messages to build a community
existance.. I don't care about this but what I care about is when u look
at the threads summary (before u click on the thread)and u find at least
2 replies for a thread, u will think that someone already helped which
is not true.. This happens all the time on Google groups.. I originally
posted my question on google but this forum is linked somehow to it..

And Scott M: If you have enough expreince you would have understood my
question from the first post.

back to the topic: yes, I solved it by using ViewState to instead of the
Session object,I meant the ViewState collection of the page object like:
ViewState("key") = value
this way when you refresh, it will call the origianl value of the
ViewState("key") even it was modified after the first submission.

Tamer

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
"tamer yousef" <tasmisr@.hotmail.com> wrote in message
news:uNph7QYyDHA.2636@.TK2MSFTNGP09.phx.gbl...
> >>People are posting mostly out of the goodness of their >>hearts.
> I guess not, some people are not, they just don't understand the
> technology and they are posting messages to build a community
> existance.. I don't care about this but what I care about is when u look
> at the threads summary (before u click on the thread)and u find at least
> 2 replies for a thread, u will think that someone already helped which
> is not true.. This happens all the time on Google groups.. I originally
> posted my question on google but this forum is linked somehow to it..
> And Scott M: If you have enough expreince you would have understood my
> question from the first post.

Don't blame me because you can not express yourself. I asked you in my
reply to be more clear about what problem you were having, your response was
that my answer was incorrect. I didn't give an answer, because you had not
supplied a question. I supplied general information about the page class
lifecycle in the hopes that this small amount of information could help you.
By the way, "you're welcome".

> back to the topic: yes, I solved it by using ViewState to instead of the
> Session object,I meant the ViewState collection of the page object like:
> ViewState("key") = value
> this way when you refresh, it will call the origianl value of the
> ViewState("key") even it was modified after the first submission.

Why are you saying "instead of the Session object" when no one had suggested
the session object in the first place?

This is what I mean, you have been unclear about what you need, what you are
trying to do and what your attempts at a solution have been. This is one of
the basic tenants of how these NG's work. If it is frustrating to you that
the people who take their valuable time can't give you an answer based on
your vauge ranting, then you need to take the advice of "g pavlov"!

You've made a lot of friends here I can tell you!
>Don't blame me because you can not express yourself. I >asked you in my
reply to be more clear about what problem >you were having, your
response was
>that my answer was incorrect.

U keep saying that my question was not clear, here is the original
question one more time:

>In the Submit button in my webform, I capture the server >side click
>event and I update session information to track the >visibilty of some
>panels in a wizard type navigation ("Next >>" and "<< >Back" buttons)..
>but the refresh button makes another event firing and >takes the whole
>thing to a Choes..

The refresh Button has a known problem of re-submitting the data. AND AS
YOU CAN READ I CLREALY mention using the SESSION object to keep track of
a submission status, again if you have experienced this problem in a
real solution you would have know how to solve it without saying to me
in your second post:

>This is more ranting and less of an explanation of what >is happening
and
>what your problem really is...

and what make it worse, is that you started explaining the life cycle of
the page object and I clearly said in my first post:

>> In the Submit button in my webform, I capture the server side click
event

which means that I did submit data, but you replied by:

>If no data was submitted prior to the
>refresh, then there is no data to repost

So you are creating your own hypothetical problem and solving it.. this
doesn't really help!
I would say it if it was my bad but clearly not, it's your
replies(which I call answers) that are not related to the problem.
Go check online on this Refresh problem and you will see how clearly
everybody know about it and nobody have given a solution for it(other
than the 2 soultions I mentioned in my first post).

I want you next time when you have a critical problem in your program to
think back about this thread and get the feeling of being stuck and
wasting your time in a thread like.. and yah u'r right, I made 2 friends
here..

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
> U keep saying that my question was not clear, here is the original
> question one more time:
> >In the Submit button in my webform, I capture the server >side click
> >event and I update session information to track the >visibilty of some
> >panels in a wizard type navigation ("Next >>" and "<< >Back" buttons)..
> >but the refresh button makes another event firing and >takes the whole
> >thing to a Choes..

There is nothing here that tells us what you are storing in session. Was is
data submitted from the form? Was it data that is related to the data
submitted from the form? UNCLEAR what you are doing with session. I'm
sorry if you feel that this is a complete explanation of what you are doing,
but the fact is, that it isn't even close!

> The refresh Button has a known problem of re-submitting the data. AND AS
> YOU CAN READ I CLREALY mention using the SESSION object to keep track of
> a submission status, again if you have experienced this problem in a
> real solution you would have know how to solve it without saying to me
> in your second post:

Here is another example of your contempt. I usually don't insult the people
trying to help me. Now to business...There is (and never was) a known
"problem" with the refresh button. The way the refresh button works is a
matter of how HTML works and if you had any REAL experience with HTML, you
would know that. It's not a bug, it's by design.

> >This is more ranting and less of an explanation of what >is happening
> and
> >what your problem really is...
> and what make it worse, is that you started explaining the life cycle of
> the page object and I clearly said in my first post:
> >> In the Submit button in my webform, I capture the server side click
> event
> which means that I did submit data, but you replied by:
> >If no data was submitted prior to the
> >refresh, then there is no data to repost
> So you are creating your own hypothetical problem and solving it.. this
> doesn't really help!

No, you are taking what I said out of context to server your own arrogance!
You said: "the refresh button resubmits the data to
the server exactly the same as submitting the form for the first time" and I
corrected you by saying that "PostBack occurs when form data is submitted.
A refresh does not always accomplish this." which is ABSOLUTELY TRUE, if you
had any REAL experience with ASP.NET, you'd know that.

> I would say it if it was my bad but clearly not, it's your
> replies(which I call answers) that are not related to the problem.
> Go check online on this Refresh problem and you will see how clearly
> everybody know about it and nobody have given a solution for it(other
> than the 2 soultions I mentioned in my first post).

Again, this is not a problem, which is why no one is giving you a solution.
You've been very clear from the beginning what you DON'T want to hear. By
being ignorant like this ("redirection to the same page/ saving state in a
database is dumb and
should not be mentioned as an answer") tells us all that it is YOU who has
no real practical experience with ASP.NET / HTML.

> I want you next time when you have a critical problem in your program to
> think back about this thread and get the feeling of being stuck and
> wasting your time in a thread like.. and yah u'r right, I made 2 friends
> here..

And I wish that the next time you extend your hand to help someone, that
they bite it right off!!
Real funny, I have enough understanding and practical experince with
HTML and .Net.
If you don't understand the question don't create your own assumptions
and answers for these assumptions.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Friday, March 16, 2012

on method for handling dynamic control events

Hi Paul,
Can you pass the codes to me? I am running into some troubles with Context
menu. I had tried the 'CuttingEdge0502' context menu which is downloadable i
n
the net. I tried to add this control dynamically but it seems nothing appear
s
when I activate it. Dunno how to continue. U come across this control?
Thanks
"PJ6" wrote:

> After a couple of months of learning ASP.NET, I think I have something wor
th
> sharing.
> The purpose of this example was to create a web control that would get its
> code fired on postback, even if had been dynamically added from code withi
n
> a user event such as from a button click.
> If you like this idea and/or have something to add to it please let me kno
w.
> Paul
>
>It's all there as an attachment in my original post. I can post in in plain
text here if you can't see it.
Paul
"JJ" <JJ@.discussions.microsoft.com> wrote in message
news:E41467C7-3AC5-404E-AB4C-B4D593648983@.microsoft.com...
> Hi Paul,
> Can you pass the codes to me? I am running into some troubles with Context
> menu. I had tried the 'CuttingEdge0502' context menu which is downloadable
> in
> the net. I tried to add this control dynamically but it seems nothing
> appears
> when I activate it. Dunno how to continue. U come across this control?
> Thanks
> "PJ6" wrote:
>
Hi Paul,
Can't see the attachment. Thks!
"PJ6" wrote:

> It's all there as an attachment in my original post. I can post in in plai
n
> text here if you can't see it.
> Paul
> "JJ" <JJ@.discussions.microsoft.com> wrote in message
> news:E41467C7-3AC5-404E-AB4C-B4D593648983@.microsoft.com...
>
>

on method for handling dynamic control events

Hi Paul,

Can you pass the codes to me? I am running into some troubles with Context
menu. I had tried the 'CuttingEdge0502' context menu which is downloadable in
the net. I tried to add this control dynamically but it seems nothing appears
when I activate it. Dunno how to continue. U come across this control?

Thanks

"PJ6" wrote:

> After a couple of months of learning ASP.NET, I think I have something worth
> sharing.
> The purpose of this example was to create a web control that would get its
> code fired on postback, even if had been dynamically added from code within
> a user event such as from a button click.
> If you like this idea and/or have something to add to it please let me know.
> Paul
>It's all there as an attachment in my original post. I can post in in plain
text here if you can't see it.

Paul

"JJ" <JJ@.discussions.microsoft.com> wrote in message
news:E41467C7-3AC5-404E-AB4C-B4D593648983@.microsoft.com...
> Hi Paul,
> Can you pass the codes to me? I am running into some troubles with Context
> menu. I had tried the 'CuttingEdge0502' context menu which is downloadable
> in
> the net. I tried to add this control dynamically but it seems nothing
> appears
> when I activate it. Dunno how to continue. U come across this control?
> Thanks
> "PJ6" wrote:
>> After a couple of months of learning ASP.NET, I think I have something
>> worth
>> sharing.
>>
>> The purpose of this example was to create a web control that would get
>> its
>> code fired on postback, even if had been dynamically added from code
>> within
>> a user event such as from a button click.
>>
>> If you like this idea and/or have something to add to it please let me
>> know.
>>
>> Paul
>>
>>
>
Hi Paul,

Can't see the attachment. Thks!

"PJ6" wrote:

> It's all there as an attachment in my original post. I can post in in plain
> text here if you can't see it.
> Paul
> "JJ" <JJ@.discussions.microsoft.com> wrote in message
> news:E41467C7-3AC5-404E-AB4C-B4D593648983@.microsoft.com...
> > Hi Paul,
> > Can you pass the codes to me? I am running into some troubles with Context
> > menu. I had tried the 'CuttingEdge0502' context menu which is downloadable
> > in
> > the net. I tried to add this control dynamically but it seems nothing
> > appears
> > when I activate it. Dunno how to continue. U come across this control?
> > Thanks
> > "PJ6" wrote:
> >> After a couple of months of learning ASP.NET, I think I have something
> >> worth
> >> sharing.
> >>
> >> The purpose of this example was to create a web control that would get
> >> its
> >> code fired on postback, even if had been dynamically added from code
> >> within
> >> a user event such as from a button click.
> >>
> >> If you like this idea and/or have something to add to it please let me
> >> know.
> >>
> >> Paul
> >>
> >>
> >>
>

On postback, EVENTTARGET is populated but IsPostback == false, no events fire?!

I am having a very odd problem. On a page that was working until very
recently we are now encountering the following situation:

The page is a very basic fill in the blank form used for changing ones
password in a forms based authentication scenario. After the user fills out
the form and clicks the Change Password button, the page simply reloads as
if nothing happened. We turned on page tracing and also added the following
lines to the PageLoad event:

Trace.Write( Request.Form["__EVENTTARGET"] );
Trace.Write( cmdChangePassword.UniqueID );
Trace.Write( Page.IsPostback );

From which we get:
ctl00$cphMain$cmdChangePassword
ctl00$cphMain$cmdChangePassword
false

The first two values tell me that IsPostback should be true and that the
cmdChangePassword click event should fire. But IsPostback is false and the
cmdChangePassword_OnClick event handler is never called.

As I said this was working and now suddenly stopped. Any ideas?

--KenIsPostback is a test if "__VIEWSTATE" is not empty and valid. use
fiddler to check your requests.

-- bruce (sqlwork.com)

Kenneth Baltrinic wrote:

Quote:

Originally Posted by

I am having a very odd problem. On a page that was working until very
recently we are now encountering the following situation:
>
The page is a very basic fill in the blank form used for changing ones
password in a forms based authentication scenario. After the user fills out
the form and clicks the Change Password button, the page simply reloads as
if nothing happened. We turned on page tracing and also added the following
lines to the PageLoad event:
>
Trace.Write( Request.Form["__EVENTTARGET"] );
Trace.Write( cmdChangePassword.UniqueID );
Trace.Write( Page.IsPostback );
>
From which we get:
ctl00$cphMain$cmdChangePassword
ctl00$cphMain$cmdChangePassword
false
>
The first two values tell me that IsPostback should be true and that the
cmdChangePassword click event should fire. But IsPostback is false and the
cmdChangePassword_OnClick event handler is never called.
>
As I said this was working and now suddenly stopped. Any ideas?
>
--Ken
>
>