User control syntax

T

Tony

Hi,
What's wrong in my code ??
I'm new to C# and working on somebody else application
developped in C#.
I have a LinkButton in a user control page,
the LinkButton log out the user when he click it.
here is the code:

<asp:linkbutton ID="logOut_" OnClick="logOut_Click"
Runat="server">Log Out</asp:LinkButton>

and the code behind is :

protected System.Web.UI.WebControls.LinkButton logOut_;
public void logOut_Click (object sender, EventArgs e)
{
FormsAuthentication.SignOut();
Response.Redirect(Request.ApplicationPath);
}

when the page that call the user control load, a
javascript type error message say: "expected identifier"

if I click this LinkButton I get an error:
"Microsoft Jscript Runtime error: Object expected"

when I hilight the code where the execution stopped that's
what is displayed:
__doPostBack('TabStrip1$logOut_','')


Thank you for any help.
 
J

Jeffrey Tan[MSFT]

Hi Tony,

Based on my understanding, when you load the user control and click the
linkbutton you will get an error.
How do you load your user control in your page? Normally, we drag the .ascx
file into the web page from the "Solution Explorer".
For your linkbutton click problem, I still can not reproduce out. Actually,
I do like this:
public void logOut_Click(object sender, System.EventArgs e)
{
logOut_.Text ="Clicked";
}

I think you should check if your FormsAuthentication refer to the correct
element.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hi Jeffrey,
the user control include a linkButton called "logOut_".

the user control is inserted in the main page through:
<%@ Register TagPrefix="ucl" TagName="myUserControlName"
Src="myUserControlName.ascx" %>

the page run in Debug mode.

when this main page start loading, a javascript type error
message (alert box) display:
"A Runtime error occurred , do you wish to debug?
Line:26 error:expected identifier yes/No"

when I click yes/no, (even if I click 'Yes'), the main
page continue loading as normal, and the user control get
displayed.
when I clik this user control, the execution code hit the
javascript code on the main page genetrated by .Net
before it hit Page_load event, and the debuger hilight
this code line:
__doPostBack('myUserControlName1$logOut_',''), and display
this error:
"Microsoft JScript runtime error: Object expected".

when I view the main page source, that's what the
LinkButton from the user control looks like:
<a id="myUserControlName1_logOut_"
href="javascript:__doPostBack('myUserControlName1
$logOut_','')">Log Out</a>

and that's what is generating the error.

thank you again for any help
 
J

Jeffrey Tan[MSFT]

Hi

Based on my understanding, your "A Runtime error occurred , do you wish to
debug?Line:26 error:expected identifier yes/No" generate when you
run the web form.
But I do not understand why your
__doPostBack('myUserControlName1$logOut_','') executed before Page_load
event. Because before __doPostBack() is a client side script, and all the
client side script will be rendered "after" Page_load event.

Actully, the <a id="myUserControlName1_logOut_"
href="javascript:__doPostBack('myUserControlName1$logOut_','')">Log Out</a>
will not generate error.

I think you can try to create a new project, add a .ascx file into the
project, then do this in the .ascx file:
public void logOut_Click(object sender, System.EventArgs e)
{
logOut_.Text ="Clicked";
}

Then drag it into your web form. Does this still generate problem?


Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top