Showing posts with label event. Show all posts
Showing posts with label event. 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

Thursday, March 22, 2012

oleDBConnection not recognizing Database

Hi,
I'm using oleDBConnection to connect to SQL server. I keep getting "SQL
Server does not exist" on Open event.
The code I'm using is the following
Dim objConn As New OleDbConnection("Provider=SQLOLEDB;Data
Source=sqlserver;Database=db;User Id=user;Password=user;")

Can anyone help?

Roger

--
Axiom Software, Ltd.
400 Columbus Ave
Valhalla, NY 10595
(914) 769-8800My Data Source is a machine name. SQL server uses SQL Server and Windows
authentication.

"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:eURxE2WbDHA.1816@.TK2MSFTNGP09.phx.gbl...
> The actual message is "SQL Does not exist or access is denied." It could
be
> one or the other. First, your "Data Source" declaration - Is that a
machine
> name there? It has to be either a machine name, domain name, or an IP
> address of the machine hosting the SQL Server. Is it? If so, what
> authentication method is the server using?
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> http://www.takempis.com
> The more I learn, the less I know.
> "Roger Cantillo" <rogerc@.axiomsw.com> wrote in message
> news:eeuV2VWbDHA.3748@.TK2MSFTNGP11.phx.gbl...
> > Hi,
> > I'm using oleDBConnection to connect to SQL server. I keep getting "SQL
> > Server does not exist" on Open event.
> > The code I'm using is the following
> > Dim objConn As New OleDbConnection("Provider=SQLOLEDB;Data
> > Source=sqlserver;Database=db;User Id=user;Password=user;")
> > Can anyone help?
> > Roger
> > --
> > Axiom Software, Ltd.
> > 400 Columbus Ave
> > Valhalla, NY 10595
> > (914) 769-8800
Try substituting "Initial Catalog" for "Database" in your Connection String.
Example:

"Provider=sqloledb;Data Source=MachineName;Initial Catalog=Databasename;User
Id=UserName;Password=UserPassword;"

If that doesn't work, one of a couple of things could be wrong:

1. The machine name is not recognized across the network. Try using an IP
address instead. And make sure that the SQL Server is using TCP/IP
2. Your User Name and/or Password are incorrectly typed
3. Your UserName account doesn't have permission to access the database

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.

"Roger Cantillo" <rogerc@.axiomsw.com> wrote in message
news:evhdEuZbDHA.1180@.TK2MSFTNGP11.phx.gbl...
> My Data Source is a machine name. SQL server uses SQL Server and Windows
> authentication.
>
>
> "Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
> news:eURxE2WbDHA.1816@.TK2MSFTNGP09.phx.gbl...
> > The actual message is "SQL Does not exist or access is denied." It could
> be
> > one or the other. First, your "Data Source" declaration - Is that a
> machine
> > name there? It has to be either a machine name, domain name, or an IP
> > address of the machine hosting the SQL Server. Is it? If so, what
> > authentication method is the server using?
> > --
> > HTH,
> > Kevin Spencer
> > Microsoft MVP
> > .Net Developer
> > http://www.takempis.com
> > The more I learn, the less I know.
> > "Roger Cantillo" <rogerc@.axiomsw.com> wrote in message
> > news:eeuV2VWbDHA.3748@.TK2MSFTNGP11.phx.gbl...
> > > Hi,
> > > I'm using oleDBConnection to connect to SQL server. I keep getting
"SQL
> > > Server does not exist" on Open event.
> > > The code I'm using is the following
> > > Dim objConn As New OleDbConnection("Provider=SQLOLEDB;Data
> > > Source=sqlserver;Database=db;User Id=user;Password=user;")
> > > > > Can anyone help?
> > > > Roger
> > > > --
> > > Axiom Software, Ltd.
> > > 400 Columbus Ave
> > > Valhalla, NY 10595
> > > (914) 769-8800
> >

Friday, March 16, 2012

On page_EXIT ??

Is there an event fired when I exit from an aspx.page?

I mean, if the user clicks in any other link available on the screen, i
would like to caught thta event and pop-up , remembering to save
unsaved data...

is that possible??

Thanks

AlbertoAre you looking for Page.OnUnload ?

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Gordowey" <albertoiriarte@.gmail.com> wrote in message
news:1130431340.421969.246570@.o13g2000cwo.googlegr oups.com...
> Is there an event fired when I exit from an aspx.page?
> I mean, if the user clicks in any other link available on the screen, i
> would like to caught thta event and pop-up , remembering to save
> unsaved data...
> is that possible??
> Thanks
> Alberto
Unfortunately, there is no such thing. Since the browser is completely
disconnected from the server immediately after it loads the last item
required for that page, there's no way to trap this. You would have to so
something like create an onclick hander for each anchor on the page that
would fire some script to remind them, perhaps a message box that reminds
them and forces them to click yes to continue and leave or no and not be
redirected.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Gordowey" <albertoiriarte@.gmail.com> wrote in message
news:1130431340.421969.246570@.o13g2000cwo.googlegr oups.com...
> Is there an event fired when I exit from an aspx.page?
> I mean, if the user clicks in any other link available on the screen, i
> would like to caught thta event and pop-up , remembering to save
> unsaved data...
> is that possible??
> Thanks
> Alberto
oK thanks..thats what I thouht...its hard...put an event in each
link...

thanks!

Alberto
Hi, Mark.

according to ASP.NET 2.0 Internals :
http://msdn.microsoft.com/library/d...l/internals.asp
there *is* a Page.OnUnload event and it's a part
of the Page Lifecycle methods ( see Table 1).

Wouldn't that event do for what he apparently wants to do ?

Page.Unload inherits from Control :

http://msdn.microsoft.com/library/d...emberstopic.asp

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Mark Fitzpatrick" <markfitz@.fitzme.com> wrote in message
news:eEaKtax2FHA.2268@.TK2MSFTNGP15.phx.gbl...
> Unfortunately, there is no such thing. Since the browser is completely disconnected from
> the server immediately after it loads the last item required for that page, there's no
> way to trap this. You would have to so something like create an onclick hander for each
> anchor on the page that would fire some script to remind them, perhaps a message box
> that reminds them and forces them to click yes to continue and leave or no and not be
> redirected.
> Hope this helps,
> Mark Fitzpatrick
> Microsoft MVP - FrontPage

> "Gordowey" <albertoiriarte@.gmail.com> wrote in message
> news:1130431340.421969.246570@.o13g2000cwo.googlegr oups.com...
>> Is there an event fired when I exit from an aspx.page?
>>
>> I mean, if the user clicks in any other link available on the screen, i
>> would like to caught thta event and pop-up , remembering to save
>> unsaved data...
>>
>> is that possible??
>>
>> Thanks
>>
>> Alberto
Not server side (the server would do once the page is navigated away).

But you could perhaps use the onbeforeunload client side event :
http://msdn.microsoft.com/library/d...eforeunload.asp

--
Patrice

"Gordowey" <albertoiriarte@.gmail.com> a crit dans le message de
news:1130432315.940034.103810@.f14g2000cwb.googlegr oups.com...
oK thanks..thats what I thouht...its hard...put an event in each
link...

thanks!

Alberto
You must come from a windows forms world. While it sounds like the
right event, and it would be if we we're using a windows form, OnUnload
fires before a page is sent back to the user. It goes something like
this:

Client Request --> OnLoad --> Some more events -->OnUnload --> Response
back to client

Hooking into the OnUnload event simply allows you to do stuff as a last
step before a rendered page is sent back to the client.

As another poster mentioned, you could hook into the javascript
onbeforeunload event with something like this:

<script>
function CheckUnload()
{
if (("1" == document.forms["Form1"].IsChanged.Value))
{
if (confirm("You have unsaved changes. Click OK to save changes."))
{
document.forms["Form1"].submit();
alert("Changes saved.");

return false;
}
}
}
</script
<body onbeforeunload="CheckUnload()">...

Best of luck,

Matt Furnari
Thanks Patrice, that link helps me a lot...

unfortunatelly this systema must be developed in webforms...not
winforms...)

Thanks ALL@.@.
That still wouldn't work if the user just closes the browser or types a new
web address into the address bar, selects a favorite, etc.

The only reliable way I know of is to handle the onbeforeunload event in the
browser. In this handler, you then prompt the user to cancel the operation,
and maybe make a server side call to save the data. However, the caveat is
that this event fires even if the user is just navigating to the next
logical page in your application via a link or button. So, you have to have
code that keeps track of what the user has been doing, so your handler knows
if this event is being called because the user is actually trying to close
your application, or just because the user is making a request via some
functionality in your application, and so the current page is being
unloaded.

"Mark Fitzpatrick" <markfitz@.fitzme.com> wrote in message
news:eEaKtax2FHA.2268@.TK2MSFTNGP15.phx.gbl...
> Unfortunately, there is no such thing. Since the browser is completely
> disconnected from the server immediately after it loads the last item
> required for that page, there's no way to trap this. You would have to so
> something like create an onclick hander for each anchor on the page that
> would fire some script to remind them, perhaps a message box that reminds
> them and forces them to click yes to continue and leave or no and not be
> redirected.
> Hope this helps,
> Mark Fitzpatrick
> Microsoft MVP - FrontPage
> "Gordowey" <albertoiriarte@.gmail.com> wrote in message
> news:1130431340.421969.246570@.o13g2000cwo.googlegr oups.com...
>> Is there an event fired when I exit from an aspx.page?
>>
>> I mean, if the user clicks in any other link available on the screen, i
>> would like to caught thta event and pop-up , remembering to save
>> unsaved data...
>>
>> is that possible??
>>
>> Thanks
>>
>> Alberto
>>
re:
> You must come from a windows forms world.

heh, heh... I don't.

It's just that it's *really* hard to bat for 1.000.

Baseball players win batting championships with .310 batting averages.
This league is a little tougher than that.

;-)

Thanks...

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"sp3d2orbit" <mfurnari@.gmail.com> wrote in message
news:1130434360.479309.211030@.o13g2000cwo.googlegr oups.com...
> You must come from a windows forms world. While it sounds like the
> right event, and it would be if we we're using a windows form, OnUnload
> fires before a page is sent back to the user. It goes something like
> this:
> Client Request --> OnLoad --> Some more events -->OnUnload --> Response
> back to client
> Hooking into the OnUnload event simply allows you to do stuff as a last
> step before a rendered page is sent back to the client.
> As another poster mentioned, you could hook into the javascript
> onbeforeunload event with something like this:
> <script>
> function CheckUnload()
> {
> if (("1" == document.forms["Form1"].IsChanged.Value))
> {
> if (confirm("You have unsaved changes. Click OK to save changes."))
> {
> document.forms["Form1"].submit();
> alert("Changes saved.");
> return false;
> }
> }
> }
> </script>
> <body onbeforeunload="CheckUnload()">...
>
> Best of luck,
> Matt Furnari
This is *not* Windows forms. I don't really like the ambigious webform term.
A webform runs server side to produce an HTML output that is transmited and
rendered client side. This event is a client side event that can be handle
within this HTML page to be warn when the user is about to navigate way from
its current browser window.

In a web application, "web pages" have a double personality : they have a
representation on the server (as .NET code rendering HTML code) but you can
also handle a number of things client side from the produced HTML page
(DHTML/JavaScript).

--
Patrice

"Gordowey" <albertoiriarte@.gmail.com> a crit dans le message de
news:1130435385.042534.258600@.g14g2000cwa.googlegr oups.com...
> Thanks Patrice, that link helps me a lot...
> unfortunatelly this systema must be developed in webforms...not
> winforms...)
> Thanks ALL@.@.
This is a problem for all web applications.

If I have a complicated application where items are saved and updated
on mulitple pages, I save all work the user has done immediately. You
cannot assume that you can save the user's work at a another point in
time. Even if you captured every link,you can't control when the user
closes the web brower (I do it accidently all the time) or hits the
back button.

On page_EXIT ??

Is there an event fired when I exit from an aspx.page?
I mean, if the user clicks in any other link available on the screen, i
would like to caught thta event and pop-up , remembering to save
unsaved data...
is that possible'
Thanks
AlbertoAre you looking for Page.OnUnload ?
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Gordowey" <albertoiriarte@.gmail.com> wrote in message
news:1130431340.421969.246570@.o13g2000cwo.googlegroups.com...
> Is there an event fired when I exit from an aspx.page?
> I mean, if the user clicks in any other link available on the screen, i
> would like to caught thta event and pop-up , remembering to save
> unsaved data...
> is that possible'
> Thanks
> Alberto
>
Unfortunately, there is no such thing. Since the browser is completely
disconnected from the server immediately after it loads the last item
required for that page, there's no way to trap this. You would have to so
something like create an onclick hander for each anchor on the page that
would fire some script to remind them, perhaps a message box that reminds
them and forces them to click yes to continue and leave or no and not be
redirected.
Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
"Gordowey" <albertoiriarte@.gmail.com> wrote in message
news:1130431340.421969.246570@.o13g2000cwo.googlegroups.com...
> Is there an event fired when I exit from an aspx.page?
> I mean, if the user clicks in any other link available on the screen, i
> would like to caught thta event and pop-up , remembering to save
> unsaved data...
> is that possible'
> Thanks
> Alberto
>
oK thanks..that=B4s what I thouht...it=B4s hard...put an event in each
link...
thanks!
Alberto
Hi, Mark.
according to ASP.NET 2.0 Internals :
http://msdn.microsoft.com/library/d...br />
nals.asp
there *is* a Page.OnUnload event and it's a part
of the Page Lifecycle methods ( see Table 1).
Wouldn't that event do for what he apparently wants to do ?
Page.Unload inherits from Control :
http://msdn.microsoft.com/library/d...emberstopic.asp
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Mark Fitzpatrick" <markfitz@.fitzme.com> wrote in message
news:eEaKtax2FHA.2268@.TK2MSFTNGP15.phx.gbl...
> Unfortunately, there is no such thing. Since the browser is completely dis
connected from
> the server immediately after it loads the last item required for that page
, there's no
> way to trap this. You would have to so something like create an onclick ha
nder for each
> anchor on the page that would fire some script to remind them, perhaps a m
essage box
> that reminds them and forces them to click yes to continue and leave or no
and not be
> redirected.
> Hope this helps,
> Mark Fitzpatrick
> Microsoft MVP - FrontPage
> "Gordowey" <albertoiriarte@.gmail.com> wrote in message
> news:1130431340.421969.246570@.o13g2000cwo.googlegroups.com...
Not server side (the server would do once the page is navigated away).
But you could perhaps use the onbeforeunload client side event :
http://msdn.microsoft.com/library/d...eforeunload.asp
Patrice
"Gordowey" <albertoiriarte@.gmail.com> a crit dans le message de
news:1130432315.940034.103810@.f14g2000cwb.googlegroups.com...
oK thanks..thats what I thouht...its hard...put an event in each
link...
thanks!
Alberto
You must come from a windows forms world. While it sounds like the
right event, and it would be if we we're using a windows form, OnUnload
fires before a page is sent back to the user. It goes something like
this:
Client Request --> OnLoad --> Some more events -->OnUnload --> Response
back to client
Hooking into the OnUnload event simply allows you to do stuff as a last
step before a rendered page is sent back to the client.
As another poster mentioned, you could hook into the javascript
onbeforeunload event with something like this:
<script>
function CheckUnload()
{
if (("1" == document.forms["Form1"].IsChanged.Value))
{
if (confirm("You have unsaved changes. Click OK to save changes."))
{
document.forms["Form1"].submit();
alert("Changes saved.");
return false;
}
}
}
</script>
<body onbeforeunload="CheckUnload()">...
Best of luck,
Matt Furnari
Thanks Patrice, that link helps me a lot...
unfortunatelly this systema must be developed in webforms...not
winforms...)
Thanks ALL@.@.
That still wouldn't work if the user just closes the browser or types a new
web address into the address bar, selects a favorite, etc.
The only reliable way I know of is to handle the onbeforeunload event in the
browser. In this handler, you then prompt the user to cancel the operation,
and maybe make a server side call to save the data. However, the caveat is
that this event fires even if the user is just navigating to the next
logical page in your application via a link or button. So, you have to have
code that keeps track of what the user has been doing, so your handler knows
if this event is being called because the user is actually trying to close
your application, or just because the user is making a request via some
functionality in your application, and so the current page is being
unloaded.
"Mark Fitzpatrick" <markfitz@.fitzme.com> wrote in message
news:eEaKtax2FHA.2268@.TK2MSFTNGP15.phx.gbl...
> Unfortunately, there is no such thing. Since the browser is completely
> disconnected from the server immediately after it loads the last item
> required for that page, there's no way to trap this. You would have to so
> something like create an onclick hander for each anchor on the page that
> would fire some script to remind them, perhaps a message box that reminds
> them and forces them to click yes to continue and leave or no and not be
> redirected.
> Hope this helps,
> Mark Fitzpatrick
> Microsoft MVP - FrontPage
> "Gordowey" <albertoiriarte@.gmail.com> wrote in message
> news:1130431340.421969.246570@.o13g2000cwo.googlegroups.com...
>
re:
> You must come from a windows forms world.
heh, heh... I don't.
It's just that it's *really* hard to bat for 1.000.
Baseball players win batting championships with .310 batting averages.
This league is a little tougher than that.
;-)
Thanks...
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"sp3d2orbit" <mfurnari@.gmail.com> wrote in message
news:1130434360.479309.211030@.o13g2000cwo.googlegroups.com...
> You must come from a windows forms world. While it sounds like the
> right event, and it would be if we we're using a windows form, OnUnload
> fires before a page is sent back to the user. It goes something like
> this:
> Client Request --> OnLoad --> Some more events -->OnUnload --> Response
> back to client
> Hooking into the OnUnload event simply allows you to do stuff as a last
> step before a rendered page is sent back to the client.
> As another poster mentioned, you could hook into the javascript
> onbeforeunload event with something like this:
> <script>
> function CheckUnload()
> {
> if (("1" == document.forms["Form1"].IsChanged.Value))
> {
> if (confirm("You have unsaved changes. Click OK to save changes."))
> {
> document.forms["Form1"].submit();
> alert("Changes saved.");
> return false;
> }
> }
> }
> </script>
> <body onbeforeunload="CheckUnload()">...
>
> Best of luck,
> Matt Furnari
>

on page refresh event fires again?

Hi Guys,
I have a ASP:Button which when clicked saves some data in the database. This works fine! But after the save if user refreshes the browser by hitting F5 or clicking the refresh button on the browser the event fires again and saves the data in the DB. How do I stop this??Clear the form of any values. Alternatively, when the user fills in values in the form, take him to another page which does the saving, then go back to the original form, clear of values. Or, move the user to another page after saving their data. A confirmation page, so to speak.