Showing posts with label webcontrols. Show all posts
Showing posts with label webcontrols. Show all posts

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

Thursday, March 22, 2012

trouble with image

Hi guys,
I'm a beginner of asp.net:( When I click a
(System.Web.UI.WebControls.)Button on a page,of course,its' click event has
been assigned,the images on this page should be refreshed,right?These
images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
happen,why?
Much thanx.Presumably because the browser has cached the image that was at that
URL previously. If you want to load a different image for each screen
refresh then add a random number, or datestamp to the URL for your
image, that way the browser receives a different URL and will
redownload the image.
"Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
news:1144079199.958679.87150@.v46g2000cwv.googlegroups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.
>
For a production environment, where the image may not change much, then I
would recommend removing the auto-generated number so that the cache
displays the image. Otherwise, the client may download more than it needs
too...<shrug>
Mythran
Thanx for your advice.My current problem: in the button click event,picture
stored in db is changed. "GetPic.aspx?id=xxx" is used to get pic from
db.What I want is after click,the image on this page should display the new
content(reload from db).But now db has updated successfully,the page is
still here,no change.
"Flinky Wisty Pomm" <Pathogenix@.gmail.com>
':1144079199.958679.87150@.v46g2000cwv.googlegroups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.
>
"removing the auto-generated number so that the cache displays the image"
Sorry but I have no idea how to remove,thanx.
"Mythran" <kip_potter@.hotmail.comREMOVETRAIL>
':eeIMsezVGHA.5044@.TK2MSFTNGP09.phx.gbl...
> "Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
> news:1144079199.958679.87150@.v46g2000cwv.googlegroups.com...
> For a production environment, where the image may not change much, then I
> would recommend removing the auto-generated number so that the cache
> displays the image. Otherwise, the client may download more than it needs
> too...<shrug>
> Mythran
>
Much thanx,Flinky Wisty Pomm && Mythran:)
I got it,add a RequiredFieldValidator on the page and bind it to any
control,then nothing bother me:) But who can tell me why?puzzling
"tjer" <tj@.tj.edu.cn> д?:#jIoo1xVGHA.5288@.TK2MSFTNGP14.phx.gbl...
> Hi guys,
> I'm a beginner of asp.net:( When I click a
> (System.Web.UI.WebControls.)Button on a page,of course,its' click event
has
> been assigned,the images on this page should be refreshed,right?These
> images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
> happen,why?
> Much thanx.
>

trouble with image

Hi guys,

I'm a beginner of asp.net:( When I click a
(System.Web.UI.WebControls.)Button on a page,of course,its' click event has
been assigned,the images on this page should be refreshed,right?These
images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
happen,why?

Much thanx.Presumably because the browser has cached the image that was at that
URL previously. If you want to load a different image for each screen
refresh then add a random number, or datestamp to the URL for your
image, that way the browser receives a different URL and will
redownload the image.
"Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
news:1144079199.958679.87150@.v46g2000cwv.googlegro ups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.

For a production environment, where the image may not change much, then I
would recommend removing the auto-generated number so that the cache
displays the image. Otherwise, the client may download more than it needs
too...<shrug
Mythran
Thanx for your advice.My current problem: in the button click event,picture
stored in db is changed. "GetPic.aspx?id=xxx" is used to get pic from
db.What I want is after click,the image on this page should display the new
content(reload from db).But now db has updated successfully,the page is
still here,no change.

"Flinky Wisty Pomm" <Pathogenix@.gmail.com>
??:1144079199.958679.87150@.v46g2000cwv.googleg roups.com...
> Presumably because the browser has cached the image that was at that
> URL previously. If you want to load a different image for each screen
> refresh then add a random number, or datestamp to the URL for your
> image, that way the browser receives a different URL and will
> redownload the image.
"removing the auto-generated number so that the cache displays the image"

Sorry but I have no idea how to remove,thanx.

"Mythran" <kip_potter@.hotmail.comREMOVETRAIL>
??:eeIMsezVGHA.5044@.TK2MSFTNGP09.phx.gbl...
> "Flinky Wisty Pomm" <Pathogenix@.gmail.com> wrote in message
> news:1144079199.958679.87150@.v46g2000cwv.googlegro ups.com...
> > Presumably because the browser has cached the image that was at that
> > URL previously. If you want to load a different image for each screen
> > refresh then add a random number, or datestamp to the URL for your
> > image, that way the browser receives a different URL and will
> > redownload the image.
> For a production environment, where the image may not change much, then I
> would recommend removing the auto-generated number so that the cache
> displays the image. Otherwise, the client may download more than it needs
> too...<shrug>
> Mythran
Much thanx,Flinky Wisty Pomm && Mythran:)

I got it,add a RequiredFieldValidator on the page and bind it to any
control,then nothing bother me:) But who can tell me why?puzzling

"tjer" <tj@.tj.edu.cn> д?:#jIoo1xVGHA.5288@.TK2MSFTNGP14.phx.gbl ...
> Hi guys,
> I'm a beginner of asp.net:( When I click a
> (System.Web.UI.WebControls.)Button on a page,of course,its' click event
has
> been assigned,the images on this page should be refreshed,right?These
> images' imageurl are such as "getpic.aspx?id=xxx".But refresh doesn't
> happen,why?
> Much thanx.