RE: GetPostBackEventReference - dynamic argument

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hello Monty,

From your description, you're developing a custom ASP.NET webserver control
which need to do the following things:

** include multiple <div> elements
** let the each <div> raise a control postback event when user click on it
** pass the client-side <div> ID (which trigger the postback event) into
the __doPostBack client procedure,

is this correct?

Based on my research, when you use
Page.ClientScript.GetPostBackEventReference method, it will always treat
the second parameter(argument) as a plain string text and the output script
statement will wrapper it with a single quote pair( ''). If you want to
embeded script code, you can do an additional replace on the returned
script statement. e.g.

========================
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

string dopost1 =
Page.ClientScript.GetPostBackEventReference(this, "{0}");
string dopost2 =
Page.ClientScript.GetPostBackEventReference(this, "{0}");


div1.Attributes["onclick"] = dopost1.Replace("'{0}'",
"event.srcElement.id");
div2.Attributes["onclick"] = dopost2.Replace("'{0}'",
"event.srcElement.id");
}
=========================

Or if you're also attaching an "onclick" handle for each "<div>" tag, you
can consider directly embeded the div's "ClientID" statically, e.g.

===================
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

string dopost1 =
Page.ClientScript.GetPostBackEventReference(this, div1.ClientID);
string dopost2 =
Page.ClientScript.GetPostBackEventReference(this, div2.ClientID);


div1.Attributes["onclick"] = dopost1;
div2.Attributes["onclick"] = dopost2;
}
=========================

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.




.



Relevant Pages

  • Re: Question about ReadLine UTF8 line truncation
    ... when you use StreamReader with UTF8 encoding to ... embeded the string in code since there are some particular chars that need ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: MailMessage-Object error - net 1.1 , VS 2003
    ... at EmailSys01.EmailerForm.InitAndSendEmail(String mailTo, String subject, ... Exception has been thrown by the target of an invocation. ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework)
  • RE: setting BindingSource data types from an XML data source
    ... The ValueType property of DataGridViewColumn can not be used to convert all ... the values in that column from string to numeric type. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Help Preserving the Character Case of a string...
    ... BTJohns" to "Btjohns". ... first letter of a string to see if you could work around the issue. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.access.formscoding)
  • RE: String Concatenation (FTP)
    ... I have tried the below of assigning the size of the buffer to 1000 it ... the string. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.vsnet.general)