Showing posts with label usercontrol. Show all posts
Showing posts with label usercontrol. Show all posts

Wednesday, March 28, 2012

How do I use JavaScriptSerializer on only certain properties of an object?

I have an object that inherits from UserControl. I want to seralize certain properties in this object using JavaScriptSerializer (or another method that does the same thing). Unfortunatly, if I try to seralize the control itself, I get a crash.

I am forced to make another object that contains all the properties that need to be seralized. The properites in my control then refrence the properties of that object. Though this works, it leaves my control with a bunch of properties which are effectively nothing more than pointers to another object that exists soley to make javascript seralization to work.

Is there way around this? I want to be able to use JSON on a usercontrol and be able to specify which properties I want seralized to JSON.

Try using the ScriptIgnore attribute in the properties you don't want to be serialized.

Hope this helps,

Elias.


I tried to override every virutal property on usercontrol and I still got "Cannot get inner content of because the contents are not literal."Something in my base class (usercontrol) seems to be causing problems

How Do I Reset Scroll Position Inside UpdatePanel?

Hello,

I have a UserControl inside an UpdatePanel. The UserControl contains several DIVs that I show and hide through partial postback. I want the contents of each DIV to be scrolled to the top when I show it. I have tried using the ScriptManager to set focus onto the topmost control of each DIV when I show it, but it doesn't work. I have also tried through javascript to no avail. I know this is kind of the opposite of the behavior that many folks want from AJAX, but I need it for this piece of my application. I have tried searching but all examples are page-centric, not usercontrol-centric and speak to SmartNavigation.

Any help is appreciated.

Brendan

not sure if this would help, but I found something interestingin terms of firing off some js code during a partial page update :

http://ajax.asp.net/docs/ClientReference/Sys.WebForms/PageRequestManagerClass/default.aspx

It was particularly useful for displaying a message to the user to indicate something was happening...

Good luck,

Bob


I ended up just using this in the codebehind of the ascx:

ScriptManager.RegisterStartupScript(Page,typeof(PageTemplate),"Focus","focus();",true);

And including this function in a .js file (one line for each section):

function focus() {
try { window.location.href='#IA'; } catch (err) {}
try { window.location.href='#IB'; } catch (err) {}
try { window.location.href='#IC'; } catch (err) {}
try { window.location.href='#ID'; } catch (err) {}
try { window.location.href='#IIA'; } catch (err) {}
try { window.location.href='#IIB'; } catch (err) {}
try { window.location.href='#IIC'; } catch (err) {}
}

Seems to work on all but the initial page change, which is 'good enough' for me at this stage.