Posted
on Jun 27, 2011
(permalink)
In order to control the width and height of radalert and radconfirm, do the following:
1) Add the following markup in your aspx page or in your master page.
<form id="form1" runat="server">
<!--The span ruler is placeholder to temporarily hold message to calculate width and height -->
<span id="ruler" style="visibility: hidden; white-space: nowrap;"></span>
2) Add following script into your page or Master Page.
<script language="javascript" type="text/javascript">
function calculateWidthHeight(message, widthObj, heightObj) {
var fontHeight = 12;
width = 250;
heightObj.height = 100;
widthObj.width = message.visualLength();
if (widthObj.width > 400)
{
heightObj.height = heightObj.height + (fontHeight * widthObj.width / 400);
widthObj.width = 400;
}
else
{
widthObj.width = widthObj.width+ 100;
}
}
function ShowAlert(Title,Message) {
var heightObj = new Object();
heightObj.height = 0;
var widthObj = new Object();
widthObj.width = 0;
calculateWidthHeight(Message, widthObj, heightObj);
radalert(Message, widthObj.width, heightObj.height, Title);
}
function ShowConfirm(Title, Message,CallbackFunction) {
var heightObj = new Object();
heightObj.height = 0;
var widthObj = new Object();
widthObj.width = 0;
calculateWidthHeight(Message, widthObj, heightObj);
radconfirm(Message, CallbackFunction, widthObj.width, heightObj.height, null, Title);
}
String.prototype.visualLength = function () {
var ruler = document.getElementById("ruler");
ruler.innerHTML = this;
return ruler.offsetWidth;
}
</script>
3) Now you can call ShowAlert() or ShowConfirm() method
say:
<input type="button" value="Show Alert" onclick="ShowAlert('My Alert Title','My Alert Message, this can be any length')" />
<input type="button" value="Show Confirm" onclick="ShowConfirm('My confirm Title','My descrition, can be any length',null)" />
4) Of course you need to add ScriptManager and RadWindow to your page.
Cheers
Binay Rana
Nepal