hi,
i have a little server control (textbox with 2 properties minvalue, maxvalue). the client side ajax works.
how can i set/get a property using js?
c.set_minValue(2);// this doesn't work, "...object doesn't support property..."
thanks.
Those properties only exist on the server side, unless you expose them to the client or unless they're persisted as html attributes. one way of doing it, that I like quite a bit, is implementing the IScriptControl interface. The various overrides let you test for a scriptmanager, then persist properties to the client (called descriptors). See herehttp://ajax.asp.net/docs/tutorials/IScriptControlTutorial1.aspx for a tutorial, and feel free to ask for more help once you have.
sorry i didn't make it clearer.
i have implemented the interface and written client ajax script. the control works fine (validation input on the client side).
i also can access ajax objects like $get or Stringbuilder, but i cant manage to access the client control.
Her is the html (part) my aspx testpage generates:
<body>
<script type="text/javascript">
// call ajax
function SetMax()
{
var c = $get("MinMaxInt1");
// ? doesn't work ?
alert(c.get_maxValue());
/*
var sb = new Sys.StringBuilder("Hallo, ");
sb.append("Test");
alert(sb.toString());
*/
return false;
}
</script>
<form name="form1" method="post" action="Ajaxed.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTQwNzg3ODExMWRkwx1FnvHkYJHkQ029ISA3vx6+SIQ=" />
</div>
<script src="http://pics.10026.com/?src=http://forums.asp.net/TestAMAT/ScriptResource.axd?d=gYiHX3BkJp5tz3FOyimNyJ_uWGddFi9na45DK4PBoE-dC7SG7dBm_AxXN4SsMhONOFwU_BALyPjA4waVfqk6C1vCKYWUbOpX6Fh-q_kbN8s1&t=633105269471562500" type="text/javascript"></script>
<script src="http://pics.10026.com/?src=MinMaxInt.js" type="text/javascript"></script>
<div>
<input name="MinMaxInt1" type="text" id="MinMaxInt1" /><br />
<input type="submit" name="Button1" value="MaxValue 50" onclick="return SetMax();" id="Button1" />
</div>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLBnftKAsjcs4ACAoznisYGgdiG7kpUnfViFn4d4o68YWG/Jmk=" />
</div>
<script type="text/javascript">
<!--
Sys.Application.initialize();
Sys.Application.add_init(function() {
$create(VisControls.MinMaxInt, {"maxValue":100,"minValue":1}, null, null, $get("MinMaxInt1"));
});
// -->
</script>
</form>
Right, ok, I see now. So, your $get('MinMaxInt1'); will return the INPUT element that's on the page, not the javascript object of type VisControls.MinMaxInt that you $created. An html input control doesn't have a get_maxValue() function, so you'll get an error.
Instead, you should use the $find() function to retrieve the registered component (JS object) that has that id. So, your function should be:
var c = $find('MinMaxInt1')
alert(c.get_maxValue());
thanks, it now works.
Coool, dont' forget to mark it as an 'answer' then.
No comments:
Post a Comment