Showing posts with label programatically. Show all posts
Showing posts with label programatically. Show all posts

Saturday, March 31, 2012

triggering SQLDATASOURCE insert or update command programatically?

Is there any way to initiate a sqldatasource insert from code in place
of the button with commandname=insert or insert?
I have a formview with a datasource with an insert command on a
button. When the button is selected the insert is performed.
Say I have another button on the form with no command syntax that calls
a some sub. Is there any way to call the same sqldatasource insert
function from code? in debug when I look at the onclick sub that I am
calling when the insert button is pressed, i see all the properties of
the button, like commandname=insert, but that sub is not the real deal
and is infact not even doing anything.
Thanks.Hi,
Have you tried calling the Insert method of the sqldatasource directly, it
should do what you want
Regards,
Mohamed Mosalem
http://mosalem.blogspot.com
"Jason" wrote:

> Is there any way to initiate a sqldatasource insert from code in place
> of the button with commandname=insert or insert?
> I have a formview with a datasource with an insert command on a
> button. When the button is selected the insert is performed.
> Say I have another button on the form with no command syntax that calls
> a some sub. Is there any way to call the same sqldatasource insert
> function from code? in debug when I look at the onclick sub that I am
> calling when the insert button is pressed, i see all the properties of
> the button, like commandname=insert, but that sub is not the real deal
> and is infact not even doing anything.
> Thanks.
>
somebody else suggested that so I tried it, but when I do that for some
reason it does not see bound fields. I had two buttons up, one calling
a sub that did what you suggested and another with no code behind doing
commandname=insert and the only the later would work.
Mohamed Mosalem wrote:
> Hi,
> Have you tried calling the Insert method of the sqldatasource directly, it
> should do what you want
> Regards,
> Mohamed Mosalem
> http://mosalem.blogspot.com
> "Jason" wrote:
>

triggering SQLDATASOURCE insert or update command programatically?

Is there any way to initiate a sqldatasource insert from code in place
of the button with commandname=insert or insert?

I have a formview with a datasource with an insert command on a
button. When the button is selected the insert is performed.

Say I have another button on the form with no command syntax that calls
a some sub. Is there any way to call the same sqldatasource insert
function from code? in debug when I look at the onclick sub that I am
calling when the insert button is pressed, i see all the properties of
the button, like commandname=insert, but that sub is not the real deal
and is infact not even doing anything.

Thanks.Hi,
Have you tried calling the Insert method of the sqldatasource directly, it
should do what you want

Regards,
Mohamed Mosalem
http://mosalem.blogspot.com
"Jason" wrote:

Quote:

Originally Posted by

Is there any way to initiate a sqldatasource insert from code in place
of the button with commandname=insert or insert?
>
I have a formview with a datasource with an insert command on a
button. When the button is selected the insert is performed.
>
Say I have another button on the form with no command syntax that calls
a some sub. Is there any way to call the same sqldatasource insert
function from code? in debug when I look at the onclick sub that I am
calling when the insert button is pressed, i see all the properties of
the button, like commandname=insert, but that sub is not the real deal
and is infact not even doing anything.
>
Thanks.
>
>


somebody else suggested that so I tried it, but when I do that for some
reason it does not see bound fields. I had two buttons up, one calling
a sub that did what you suggested and another with no code behind doing
commandname=insert and the only the later would work.
Mohamed Mosalem wrote:

Quote:

Originally Posted by

Hi,
Have you tried calling the Insert method of the sqldatasource directly, it
should do what you want
>
Regards,
Mohamed Mosalem
http://mosalem.blogspot.com
>
"Jason" wrote:
>

Quote:

Originally Posted by

Is there any way to initiate a sqldatasource insert from code in place
of the button with commandname=insert or insert?

I have a formview with a datasource with an insert command on a
button. When the button is selected the insert is performed.

Say I have another button on the form with no command syntax that calls
a some sub. Is there any way to call the same sqldatasource insert
function from code? in debug when I look at the onclick sub that I am
calling when the insert button is pressed, i see all the properties of
the button, like commandname=insert, but that sub is not the real deal
and is infact not even doing anything.

Thanks.

Triming the Back Button

Is there a way to remove items from the Back Button programatically? When a
user gets to a certain page and presses the back button I want to bypass
some of the pages that he got to on the way to that page. For example, I
don't want the user to see the forms he posted before he got to this page.
To illustrate, suppose the users sees these pages in sequence:
P1-->P2-->P3-->P4
What I want is when the user is viewing P4 and presses the back button he
goes to P1 rather than P3.Hi,
as far as I know the only way to achieve this behavior is only by
supplying your own navigation mechanism. I'll be happy to hear other
options...
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
"Ron Lautmann" <ronUNDERSCORElautmann@.pacbell.net> wrote in message
news:eARi7G3TEHA.972@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove items from the Back Button programatically? When
a
> user gets to a certain page and presses the back button I want to bypass
> some of the pages that he got to on the way to that page. For example, I
> don't want the user to see the forms he posted before he got to this page.
> To illustrate, suppose the users sees these pages in sequence:
> P1-->P2-->P3-->P4
> What I want is when the user is viewing P4 and presses the back button he
> goes to P1 rather than P3.
>
"Ron Lautmann" <ronUNDERSCORElautmann@.pacbell.net> wrote in message
news:eARi7G3TEHA.972@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove items from the Back Button programatically? When
a
> user gets to a certain page and presses the back button I want to bypass
> some of the pages that he got to on the way to that page. For example, I
> don't want the user to see the forms he posted before he got to this page.
> To illustrate, suppose the users sees these pages in sequence:
> P1-->P2-->P3-->P4
> What I want is when the user is viewing P4 and presses the back button he
> goes to P1 rather than P3.
Did I just send a blank response? Sorry if so.
There's no good way to do this. What if the user is viewing P4 and enters P3
into the browser's address bar? What if the user creates a new browser
window and has that window go to P2 while the first one goes back to P3?
This is one of the characteristics of a web application. Because you didn't
create the program the user is using (the browser), you don't have complete
control over what the user does with that program. The trick is to simply
get over it and come up with another way of accomplishing what you need.
--
John Saunders
johnwsaundersiii at hotmail

Triming the Back Button

Is there a way to remove items from the Back Button programatically? When a
user gets to a certain page and presses the back button I want to bypass
some of the pages that he got to on the way to that page. For example, I
don't want the user to see the forms he posted before he got to this page.

To illustrate, suppose the users sees these pages in sequence:

P1-->P2-->P3-->P4

What I want is when the user is viewing P4 and presses the back button he
goes to P1 rather than P3.Hi,

as far as I know the only way to achieve this behavior is only by
supplying your own navigation mechanism. I'll be happy to hear other
options...

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
"Ron Lautmann" <ronUNDERSCORElautmann@.pacbell.net> wrote in message
news:eARi7G3TEHA.972@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove items from the Back Button programatically? When
a
> user gets to a certain page and presses the back button I want to bypass
> some of the pages that he got to on the way to that page. For example, I
> don't want the user to see the forms he posted before he got to this page.
> To illustrate, suppose the users sees these pages in sequence:
> P1-->P2-->P3-->P4
> What I want is when the user is viewing P4 and presses the back button he
> goes to P1 rather than P3.
"Ron Lautmann" <ronUNDERSCORElautmann@.pacbell.net> wrote in message
news:eARi7G3TEHA.972@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove items from the Back Button programatically? When
a
> user gets to a certain page and presses the back button I want to bypass
> some of the pages that he got to on the way to that page. For example, I
> don't want the user to see the forms he posted before he got to this page.
> To illustrate, suppose the users sees these pages in sequence:
> P1-->P2-->P3-->P4
> What I want is when the user is viewing P4 and presses the back button he
> goes to P1 rather than P3.

Did I just send a blank response? Sorry if so.

There's no good way to do this. What if the user is viewing P4 and enters P3
into the browser's address bar? What if the user creates a new browser
window and has that window go to P2 while the first one goes back to P3?

This is one of the characteristics of a web application. Because you didn't
create the program the user is using (the browser), you don't have complete
control over what the user does with that program. The trick is to simply
get over it and come up with another way of accomplishing what you need.
--
John Saunders
johnwsaundersiii at hotmail

Monday, March 26, 2012

Trouble programatically getting form values on PostBack

I am using the following web controls (list shortened to not bore you!):

protected System.Web.UI.WebControls.RadioButtonList rblSymbols;
protected System.Web.UI.WebControls.CheckBox chkPublish;
protected System.Web.UI.WebControls.DropDownList ddlSubject;
protected System.Web.UI.WebControls.TextBox txtEntry;
protected System.Web.UI.WebControls.Button btnSave;
The btnSave_Click(object sender, System.EventArgs e) is properly registered in the InitializeComponent() method. Inside the btnSave_Click() method, I call another function to save to the db which works fine. However, when I attempt to reference the values of those items, they are not set properly. It's as if the IPostBackDataHandler.LoadPostData() method in the Init of the page lifecycle is not being done at all. Any ideas? So far, I have had to result to the following until this is figured out:
YUCK!:
**********************
myObj.Entry = Request["txtEntry"];
Preferred:
**********************
myObj.Entry = txtEntry.Text;
Thanks in advance for any insight you might have.
--ChadIs it possible you've disabled Viewstate at some point?

Peter,
Yes, itIS possible. In fact, I have done just that on several of my controls. Is this the problem? I will try re-enabling. I have read so much on the pros and cons of keeping it turned on. Is is safe to assume that if I wish to program as described above, I need to keep viewstate enabled?
--Chad

Heh... yeah, that could be the problem :)

ViewState is the mechanism by which your controls' properties are persisted across postbacks. If you want to grab myControl.Text, for example, you must have Viewstate enabled.

On the other hand, if you don't mind grabbing values from the Request.Form collection, you can kill Viewstate with impunity.

Cheers,


Peter - thanks for clearing this up for me! Very helpful!

--Chad