|
Hello Everybody,
I would like to know if there is something I am missing why my ASP.NET is not running the script that is embedded in the master page, I imagine that it should be running in any page using the master page (where I have the event embedded) as shown in my screenshot but to my surprise it doesn't run the alert message ..
When I click any of the images I am not seeing the alert box that I am expecting as a response to the click event ..
My code is shown below .. any help much appreciated .. thanks again:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.4.1.js" type="text/javascript" >
$('.main').ready(
function () {
alert('hello');
});
$('img').click(
function () {
alert('hello from image');
});
</script>
<script src="Scripts/myJavascriptTools.js" type="text/javascript" >
</script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
|
|
|
|
|
After http://www.w3schools.com/tags/tag_script.asp[^]
Quote: If the "src" attribute is present, the <script> element must be empty.
Put your script in separate element after jquery and it should run correctly.
<div class="signature">--
"My software never has bugs. It just develops random features."</div>
|
|
|
|
|
I am so excited it is starting to work .. I moved the script to a separate script tag as shown (just as you have advised) and it started showing up the "hello" message every time I open up a page attached to the master file .. yeeeey ...
$('.main').ready -------------- this event is working perfect
The way the code was written when the beautiful thing event I report happens is shown below:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.4.1.js" type="text/javascript" >
</script>
<script type="text/javascript" >
$('.main').ready(
function () {
alert('hello');
});
$('img').click(
function () {
alert('hello from image');
});
</script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
The one I find odd however is that the click event is still not getting triggered
for some reason .. so what I did next was try to change it to a different tag targeting paragraph tag instead of img but retain it in the same spot i.e.
$('p').click(
The result is that it still is not triggered when I click from a paragraph the way it was not working when I was clicking from an image using the original code which used the img tag.
So I decided to try changing the event to a mouseover instead of a click as shown below:
$('p').mouseover(
Unfortunately the event is still not get triggered when I move my mouse over the paragraph elements ..
So at this point I am thinking it does not seem to have
anything to do with the tag selector or the event type ..
I decided to experiment and move the code as close to the
page being called (I'd wish of course that it could be
centralized in just one page i.e. Site.master) but just
for the sake of experiment I tried putting the code in the
page itself that is being called as shown below:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript" >
$('p').click(
function () {
alert('hello from click of paragraph');
});
</script>
<h2>
Testing this page.
<asp:TreeView ID="TreeView1" runat="server">
</asp:TreeView>
</h2>
<p> testing paragraph1
</p>
<p>
testing paragraph2
</p>
<img src = "Image/coreTechnologies.png">
</asp:Content>
Unfortunately I still cannot get the click event to run
.. and right now I am scratching my head and trying to dig
in the books what I am still missing ... all help much appreciated ..thanks again and more power
|
|
|
|
|
You're executing the script before the browser has finished loading the body of the document, so there are no <img> or <p> tags for it to process.
The simplest solution is to make sure your script doesn't run before the body has been loaded:
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$('img').click(function(){
alert('hello from image');
});
});
</script>
It's also a good idea to move your scripts to the bottom of the page, just before the closing </body> tag.
If the content of the document might change after it's loaded, and you want the event handler to work on any new tags that get added, you can use jQuery's on method[^] to attach the handler at the document level:
$(document).on('click', 'img', function(){
alert('hello from image');
});
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Awesome ... thanks so much ... this has solved the problem I was having ...
It is my first time to ask a question here and not sure how to close a question
I do not know how to give this answer the five stars it deserves .. thumbs up in text
above indicates this to be the answer .. thanks again
|
|
|
|
|
I have 2 RadioButtonList
rdBtnPersonel_Status and rdBtnPersonel_FoodStatus
i wrote :
<asp:RadioButtonList runat="server" ID="rdBtnPersonel_Status" RepeatDirection="Horizontal" Width="100%"
DataSourceID="ObjDsPersonelStatuses" onclick="javascript:radioButtonListOnClick('<%#((RadiobuttonList)Container.FindControl("rdBtnPersonel_Status")).ClientID %>');">
</asp:RadioButtonList>
i want when i click rdBtnPersonel_Status , if the valu eual A the rdBtnPersonel_FoodStatus be disabled. (with javascript)
can any body help me?
|
|
|
|
|
I tried to change the flash banner text from 50% to 60% and its only show 60% in Desktops not in mobile.
Please let me know if any one have the solution detail and steps of how to fix it
modified 4-Feb-14 4:01am.
|
|
|
|
|
In if else structure when null arguments are passed to two string variables then it always hit the condition when i have set Var1 != "" && Var2 != "" why ? since nulls are passed to both then why it hits this condition ?
code:
public ActionResult ShowCalTextBox(String DateFrom, String DateTo)
{
if (DateFrom != "" && DateTo == "")
{
IEnumerable<GetEmpRec_DateResult> EmpRec_DateFrom = DataContext.GetEmpRec_Date(DateFrom, null).ToList();
ViewBag.Dates = "Records for"+" "+ DateFrom ;
return View(EmpRec_DateFrom);
}
else if (DateFrom == "" && DateTo != "")
{
IEnumerable<GetEmpRec_DateResult> EmpRec_DateTo = DataContext.GetEmpRec_Date(null, DateTo).ToList();
ViewBag.Dates = "Records for" + " " + DateTo;
return View(EmpRec_DateTo);
}
else if (DateFrom != "" && DateTo != "")
{
IEnumerable<GetEmpRec_DateResult> EmpRec_ByDate = DataContext.GetEmpRec_Date(DateFrom, DateTo).ToList();
ViewBag.Dates = "Records from" + " " + DateFrom +" "+"to"+" "+DateTo;
return View(EmpRec_ByDate);
}
else if (DateFrom == "" && DateTo == "")
{
IEnumerable<GetEmpRec_DateResult> EmpRec_Default = DataContext.GetEmpRec_Date(null, null).ToList();
ViewBag.Dates = "No date selection";
return View(EmpRec_Default);
}
return View();
}
it hits this one when i first browse this action or run this action.
else if (DateFrom == "" && DateTo != "")
|
|
|
|
|
null isn't "" (empty string)!!!
You should use String.IsNullOrEmpty(string_var) to check for both...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
How can I catch and retry if I got a duplicate keys error?
If InsertProviderMasterCommand failed due to dups go to GenerateKeys
and try again???
Try
GenerateKeys(myRow)
If InsertProviderMasterCommand(myRow) = True Then
MasterInsertCount += 1
End If
Catch ex As Exception
Throw ex
End Try
|
|
|
|
|
If you want to retry than why waste on try-catch block - do a simple while loop around the insert part...
bool bDo = true;
while(bDo)
{
GenerateKeys(myRow);
if(InsertProviderMasterCommand(myRow))
{
MasterInsertCount += 1;
bDo = false;
}
}
(I know you are a VB fan - but I can't bring myself to write that kind of code - sorry )
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Hi Friends,
I want to know some good books to refer for "ASP.Net best practices" ,I have googled the same and there are so many books available.So can any of you tell me some good book to refer depending upon your reading experiences.
Regards
|
|
|
|
|
|
Snehasish_Nandy wrote: It's my personal choice But it has nothing to do with ASP.NET.
Veni, vidi, abiit domum
|
|
|
|
|
Check this one[^] but the version is 3.5 & out of print. Book was from Apress.
Why only Books? Education Needed[^]
In Codeproject you could find more than bunch of articles on ASP.NET Best practices.
thatrajaCode converters | Education Needed
No thanks, I am all stocked up. - Luc Pattyn
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is - Henry Minute
|
|
|
|
|
You have all the answers here:
ASP.Net Best Practices[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
I have this code is web.config
<anonymousIdentification enabled="true"/>
<profile enabled="true">
<properties>
<add name="FName" type="String" allowAnonymous="true"/>
</properties>
</profile>
<authentication mode="Windows" />
and this code is default.aspx.cs page
Profile.FName = TextBox1.Text;
Response.Write("Your name is: " + Profile.FName);
after runing the page, when I enter a data to text and click on button it gives me an error and this is error:
this.SetPropertyValue("FName", value);
and on the page error is:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
So, please help me to solve this problem.
|
|
|
|
|
Hi,
i didn't find any button on that,
i have run the code , i didn't find any error.
can you please produce the full and your requirement plz.
Thanks
|
|
|
|
|
You haven't configured the database connection correctly. The default settings will try to use a local instance of SQL Express to open a database called aspnetdb.mdf in your application's App_Data folder. If you don't have SQL Express installed, then the connection will not work.
To specify the database to connect to, you'll need to define a custom provider. You'll also need to run aspnet_regsql against the database to create the objects required to support the SqlProfileProvider .
Have a look at this article for more information: Implementing User Profiles in ASP.NET - A Beginner's Guide[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Kindly help me,
actually i am learning mvc
so which is best ,like i want to use entity framework with stored procedure ,kindly help
|
|
|
|
|
|
|
I have a listview control in that i put radiobutton but i can't find when the radio button is clicked..
my code is here
<asp:ListView ID="ListView2" runat="server" ItemPlaceholderID ="BrandName" OnSelectedIndexChanged="ListView2_SelectedIndexChanged" OnSelectedIndexChanging="ListView2_SelectedIndexChanging" OnItemCommand="ListView2_ItemCommand">
<LayoutTemplate >
<ul>
<asp:PlaceHolder runat ="server" id="BrandName"></asp:PlaceHolder>
</ul>
</LayoutTemplate>
<ItemTemplate>
<li><asp:RadioButton ID="rodB1" runat="server" GroupName="G3" OnCheckedChanged="rodB1_CheckedChanged" AutoPostBack="True" /><%#Eval("Brand")%></li>
</ItemTemplate>
</asp:ListView>
|
|
|
|
|
Hi,
I think to view the controls in the list box or gridview, we need to provide some data source.
Here i have tried some code to view the radio button control in the list view.
<asp:ListView ID="lv1" GroupItemCount="3" runat="server" DataKeyNames="1" >
<LayoutTemplate>
<fieldset>
<legend>MyGroups</legend>
<asp:PlaceHolder runat="server" ID="groupPlaceholder"></asp:PlaceHolder>
</fieldset>
</LayoutTemplate>
<GroupTemplate>
<fieldset>
<legend>Individual Group</legend>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</fieldset>
</GroupTemplate>
<GroupSeparatorTemplate>
</GroupSeparatorTemplate>
<EmptyDataTemplate>No records present.</EmptyDataTemplate>
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" AutoPostBack ="true" value='<%# Eval(1)%>' /><%# Eval("Text1")%>
</ItemTemplate>
</asp:ListView>
**********************************************
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindListView()
End If
End Sub
Private Sub BindListView()
lv1.DataSource = GetData()
lv1.DataBind()
End Sub
Private Function GetData() As DataTable
Dim dt As New DataTable()
dt.Columns.Add("1", System.Type.[GetType]("System.Int32"))
dt.Columns.Add("Text1", System.Type.[GetType]("System.Int32"))
Dim k As Integer = 0
Dim strTemp As String = 10
For i As Integer = 0 To 11
Dim dr As DataRow = dt.NewRow()
dr("1") = i + 13
dr("Text1") = 10
k += 1
If k = 3 Then
strTemp = 12
k = 0
End If
dt.Rows.Add(dr)
Next
Return dt
End Function
once try this code
I can't provide the answer, but have provide some suggestions.
Prasad Vj
|
|
|
|
|
Soliciting opinions. I'm an ASP.NET dev, and I've got the opportunity to work on a project that will be in ASP.NET MVC, which I know little about. Am I right in thinking that it's a pared-down version of ASP.NET that enforces a design template and offers lots of other syntactic sugar to cover up the inner workings of standard ASP.NET, or is there more to it? I've previously done some Silverlight, but wouldn't choose to do another due to its likely demise. There's no connection between ASP.NET MVC and WPF, right? Thoughts on the future of ASP.NET MVC?
|
|
|
|