|
Hi everybody,
I'm running into some very weird (to me) behavior when I try to chain the OnClick event of a Label to an Anchor. If that isn't self-explanatory, what I'm doing is showing a Label and hiding an Anchor. When I click on the Label, the Label clicks the Anchor.
My debugging process:
-> If I hide the Label, Show the anchor and set the function directly in the OnClick event in the a tag, executes as expected
-> If I show the Label, Hide the anchor and set the function directly in the OnClick event in the asp:label tag, executes as expected
-> If I show the Label, Hide the anchor, set the function in the anchor tag and tie the Label's OnClick event to be the PostBackClientHyperlink of the anchor, the javascript function is not executed.
Clicking the Label is triggering a PostBack, but it is not executing the client-side onclick event before doing so.
I've included the relevant code below. Does anyone have enough experience in this area to know why the Anchor's onclick event is not chained to the Label?
Page Markup
<table width="82px" cellspacing="1" cellpadding="0" bgcolor="#99BADD" runat="server">
<tr runat="server">
<td runat="server">
<table width="80px" cellspacing="0" cellpadding="0" runat="server">
<tr runat="server">
<td id="trace" bgcolor="#FFFFFF" width="80px" height="16px" runat="server">
<asp:Label runat="server" visible="false" ID="lblTrace" BackColor="#99BADD" >Trace1</asp:Label>
<a id="hdnAnchor" visible="true" runat="server" onclick="return poop();" >Trace2</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
JavaScript function (assume that "txtSuccess" exists on the Page)
function poop()
{
document.getElementById('txtSuccess').value = "PooP";
}
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
lblTrace.Attributes.Add("OnClick",ClientScript.GetPostBackClientHyperlink(this.hdnAnchor, ""));
}
"I need build Skynet. Plz send code"
|
|
|
|
|
|
Sure, do you have about five years to listen, observer and learn it?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
Sorry man,
Unfortunately, this is a big issue that cannot be answered on a forum
I suggest that you buy a good book in oop
Or join a course
Then, you can find a list of very useful articles here on CodeProject that provides samples for beginners and some tricks, etc.
The message board will be useful for you only when you are developing some application and have a specific issue
However, welcome to CodeProject
foreach(Minute m in MyLife)
myExperience++;
|
|
|
|
|
Hi all,
I am trying to code a procedure in VB.Net where a user clicks on a link and the page detects the email of the person. This way I will be able to validate that it is a new user who has accessed the activation aspx page.
Currently, I have the follwing:
IF Request.QueryString("uid") > 0 THEN<br />
'activate user<br />
ELSE<br />
'display error message<br />
END IF
I can also query the DB to see if the userID is > 0 AND if the activation status is false, but it is still not specific enough. If I can include his EMAIL ADDRESS in the query, I will have solved the issue.
Thanks for your help!
|
|
|
|
|
Well because your user might have a browser but not an email client or multiple registered emails, there's no linkage between machine and email address or browser and email address so you're basically going to have to add another variable to your querysting to include their registered email (I'm assuming your link is sent out via mail a la a forum registration message).
|
|
|
|
|
Thanks for the answer! I see what you mean.. query the email that they input and send it to his email.. when it arrives back to the application, it will be there ready for me to query!
Sometimes the solution is soo simple!
Thanks again
|
|
|
|
|
My only extension would be to encrypt the value on the way out and then decode it in your page's code when they come back. Just because someone might mess around with the URL, randomly entering IDs and email combinations.
It's unlikely I'll admit but it's just one of those things I end up doing just for peace of mind.
|
|
|
|
|
Good Call.. I will do that.. I shall use an encryption algorithm.
Thanks!
|
|
|
|
|
i've declared a variable "i" in javascript in aspx file...now i want to retrieve its value in .cs file....also i've to provide the value of "i" from .cs file only.....how can we do it????
|
|
|
|
|
Could you outline the scenario please?
Javascript is client side, C# is server. You -can- pass back the value to the server using a postback or async but C# cannot simply grab a value set in client side javascript.
|
|
|
|
|
cs on the server ..
javascript on the client browser ...
declared every asp.net control with an ID that when you postback your page will display the result
is this what you are looking for ?
mydevbank.com
|
|
|
|
|
Create an ASP:HiddenField control. Set the value of that control in javascript. If you have lots of nested controls you may have to use the <%#yourHiddenCtrlName.ClientID%> trick to get the client side ID to use when setting it in javascript.
|
|
|
|
|
when partial postback is happen then accessing data from viewstate is getting problem. it is giving error like
"threw an exception of type 'System.NullReferenceException".
here i giving a small sample code by which anyone can undersdtand what i am trying to do
ASPX Page
-----------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/ecmascript">
function ReceiveServerData(rValue)
{
document.getElementById("ResultsSpan").innerHTML = rValue;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID=btn1 runat=server Text="Button1" OnClientClick="CallServer('btn1', '');" />
<asp:Button ID=btn2 runat=server Text="Button2" OnClientClick="CallServer('btn2', '');"/>
<div id="ResultsSpan"></div>
</div>
</form>
</body>
</html>
Code Page
-----------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page ,ICallbackEventHandler
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsCallback)
{
String cbReference =
Page.ClientScript.GetCallbackEventReference(this,"arg", "ReceiveServerData", "context");
String callbackScript;
callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"CallServer", callbackScript, true);
}
}
public void RaiseCallbackEvent(String eventArgument)
{
//threw an exception of type 'System.NullReferenceException
if (vwValue == "")
{
vwValue = "Hello";
}
}
public String GetCallbackResult()
{
return vwValue;
}
public string vwValue
{
get
{
if (ViewState["dt"] != null)
return ViewState["dt"].ToString();
else
return "";
}
set
{
ViewState["dt"] = value;
}
}
}
first time i assing value to viewstate when callback happen and when again callback happen then i am not getting anyvalue in viewstate which
i have stored in first call back. i just can not understand why it is happening. please help me to understand the problem and also show me the
way i can persist value in viewstate accross multile callback. please help me with a small sample code.
thanks in advance.
tbhattacharjee
|
|
|
|
|
Please edit your post and use the pre tags to format the code and markup
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
U had suggested me to right click on the image and check the path. I had tried it but it didnt work.
My prog is running on local host so the num ber keeps changing so how can i run the program.
this was the path which was poping up on selecting the image.
Friends please help me .
http://localhost:49216/ws/App_Data/pics/pic1.jpg
In asp.net this is the coding which i have provided
asp:TableCell ID="TableCell4" ColumnSpan ="2" VerticalAlign = "Top" HorizontalAlign ="Center" runat ="server">
<asp:image id="Image1" runat="server" imageurl="../../../../../App_Data/pics/pic1.jpg">
|
|
|
|
|
sowjanya3 wrote: ImageUrl="../../../../../App_Data/pics/pic1.jpg" />
Why are you making the path relative to the page it's on instead of relative to the root of your application?
i.e.
File A is at <project root="">\images\a.jpg
So in your ImageURL you make it referenced as "/images/a.jpg"
Edit: Also your thread title is misleading. This has nothing to do with IIS or using regiis.
modified on Thursday, April 1, 2010 6:04 AM
|
|
|
|
|
hey thanks for your idea and suggestion its working man
|
|
|
|
|
Don't Put Images is App_Data Folder. AFAIK, It won't be displayed from App_Data, Due to Security Reason.
Just create a folder called Images in your Application Folder and store the images over there. Use Server.MapPath() to findout the actual url of images.
Hope this will help you.
Let me know if you have any more issue.
Thanks
Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
Hey Abhiji, even though App_Data is not visible from the user end, you can still use it data putting you data files inside. I haven't tried with image files. But I used to places all my xml files inside App_Data which is accessible for the developer/coder.
|
|
|
|
|
Yes. App_Data is storage for files like Mdf, XML etc. The real advantage is that any file you place in App_Data won't be downloadable .
Those file can be accessable by developer/Coder but not from outside, because these are not downloadable. This is the reason I guess Image not showing, as they get downloaded.
Please share your input.
Cheers !
Abhijit
Codeproject MVP
|
|
|
|
|
Yeah. You are right. I just tried with a simple sample. The image in the App_Data is inaccessible. Good to know.
|
|
|
|
|
Hi,
i developed the application in .Net Framework 1.1, the same application is working other Operating System Machines except Windows 7. if i open the application in Windows 7 Machine and click any buttons the Validation controls not working. What should i do for this? should i do any setting changes for this?
|
|
|
|
|
Could you give a few more details? (i.e. code snippet) Were you using regular expression validator controls or similar? What browsers have you tried?
|
|
|
|