Howdy,
I'm not sure if this is the case, but i suspect you just amended rendered
script for another control by viewing HTML source, which is not clever idea.
ClientScriptManager class contains everything you need:
public partial class Default2 : System.Web.UI.Page, ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
string arg = String.Format("document.getElementById('{0}').abbr",
UWBranch.ClientID);
string postbackCall = ClientScript.GetCallbackEventReference(this, arg,
"null", "null");
ClientScript.RegisterClientScriptBlock(
this.GetType(),
"MyTestScript",
String.Format(TestScript, UWBranch.ClientID, postbackCall));
}
private const string TestScript =
"function ktemptest()\n" +
"{\n" +
" alert('ktemptest called...');\n" +
" try\n" +
" {\n" +
" alert(document.getElementById('{0}').abbr);\n" +
" {1};\n" +
" alert('Webform_DoCallback call over');\n" +
" }\n" +
" catch(e)\n" +
" {\n" +
" alert('Webform_DoCallback exception: ' + e);\n" +
" }\n" +
" alert('Leaving ktemptest...');\n" +
"}";
public string GetCallbackResult()
{
return string.Empty;
}
public void RaiseCallbackEvent(string eventArgument)
{
// do something with abbr vaue here
}
}
In addition, you used control.ID for the server control (runat=server). It
may accidently work, but DO NOT use it. If you embeded UWBranch control in a
panel or any container, ID rendered to the client would be different. It
would include IDs of all parent controls. Control.ClientID in conjunction
with docuemnt.getElementById() client script is recommended combination. I
can't think of any other reasons, apart from turning js to off which is
definitely not the case.
--
Milosz
Hi,
I don't think that javascript has been turned off. I've extracted the
WebForm_DoCallback call out to a separate function and called this
function in the links' onClick() event. The call to WebForm_DoCallback
has been surrounded by alert() s and enclosed in a try...catch block
and still no error is occurring: the alerts all fire and no exception
is caught - it's as if the call is simply ignored. I'm struggling with
this...
The code below causes the following messages to display in alert()s
ktemptestcalled...
<value in UWBranch.abbr>
Webform_DoCallback call over
Leaving ktemptest...
with no errors shown - and only when I'm accessing the site from a
different computer. This code works when using Visual Studio's
development server, and also when I log on to the web server that the
site's deployed on and open a browser window there. So it seems like
some sort of security or permissions thing?
<Server Side>
UWBranch.Attributes["onclick"] = String.Format("javascript:{0}",
"ktemptest()");
<Client Side>
function ktemptest()
{
alert('ktemptest called...');
try
{
alert(document.all['UWBranch'].abbr);
WebForm_DoCallback('__Page',document.all['UWBranch'].abbr,ClientCallbackScript,null,null,false);
alert('Webform_DoCallback call over');
}
catch(e)
{
alert('Webform_DoCallback exception: ' + e);
}
alert('Leaving ktemptest...');
}