I'm not sure how to even go about looking up the answer to this question, so I apologize for not having done any research before posting. I have never touched ASP.NET before. I migrated one IIS project to a different server, and it's working as intended, except for one thing. I believe the below code snippet is responsible for creating links in a table, but it's hardcoding the links to the old URL instead of the new one. I'm not sure how to edit the ASP.NET to correct the problem and point to the new server instead. Any thoughts? Is a different code snippet responsible?
The code:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvPublicPositionList" runat="server" AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="SqlDataSource_PublicPositionList" Width="800">
<Columns>
<asp:TemplateField HeaderText="Title" SortExpression="Title">
<ItemTemplate>
<asp:LinkButton ID="lbGotoJobDescription" runat="server" CausesValidation="False" CommandName="Select"
Text='<% #Eval("Title") %>' PostBackUrl='<% #Eval("URL") %>' ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource_PublicPositionList" runat="server" ConnectionString="<%$ ConnectionStrings:JobDescriptionsConnectionStringPublic2005 %>"
SelectCommand="spSelectPublicPositionList" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:JobDescriptionsConnectionStringPublic2005 %>"
SelectCommand="SELECT * FROM [tblDepartments]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>
The link format:
javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("gvPublicPositionList$ctl02$lbGotoJobDescription", "", false, "", "CORRECT LINK BUT TO OLD SERVER", false, true))
The URL is coming from some data source in the code, so you'll have to find where that's getting populated. The <% #Eval("URL") %> code means that you're bound to something called URL - could be a database value, could be a property of some object, no way to know without seeing the data source.
So find out where this control is being populated (it will probably look something like someRepeater.DataSource = someDataSource;, and that will tell you what you need to change.
Related
I am used to writing the data on the client side, then with JavaScript, validate and submit forms to a new page on server side which updated the database and then go again.
I am thinking with programming on ASP.net, it is not a good practice to do it on client side because security is better on server side.
I am trying to do this using sqlDataSources and DataBinding unsuccessfully.
On my page I have only two input boxes. These boxes are empty.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Prueba.aspx.cs"
Inherits="MaximaBR.com.Prueba" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource id="SqlDataSource1" runat="server"
DataSourceMode="DataReader"
ConnectionString="<%$ ConnectionStrings:Data %>"
SelectCommand="SELECT [idpropiedad],[propietario]
FROM [dbo].[Propiedades]
WHERE [idpropiedad] = 525293">
<SelectParameters>
<asp:ControlParameter name="idpropiedad"
controlid="idpropiedadBox" propertyname="Text" />
<asp:ControlParameter name="propietario"
controlid="propietarioBox" propertyname="Text" />
</SelectParameters>
</asp:SqlDataSource>
<asp:TextBox id="idpropiedadBox" runat="server"
DataSourceID="SqlDataSource1"></asp:TextBox>
<asp:TextBox id="propietarioBox" runat="server"
DataSourceID="SqlDataSource1"></asp:TextBox>
</div>
</form>
</body>
</html>
I have read so many articles about this but my application is on WebForms, not mvc, so I would like to do it this way.
Also, I have so many fields with responsive html, so I need to not use gridview.
It seems to me that I lost the dataview and that's what I need. I got used to working with databind on Visual Basic 6.0, but here it seems a little tricky and can't get it to work.
Maybe one of my problems is that I don't understand the WebForm Cycles times for Page Loading and others cycles times like pre render?
You need a databound server control to show / edit / update data. For a single row asp:FormView is OK.
You need to bind child controls to underlying fields. Eval for one-way binding, Bind for two-way binding.
The code may look like this.
<asp:FormView runat="server" DefaultMode="Edit" DataSourceID="SqlDataSource1">
<EditItemTemplate>
<asp:TextBox ID="idpropiedadBox" runat="server" Text='<%#Bind("idpropiedad") %>'></asp:TextBox>
<asp:TextBox ID="propietarioBox" runat="server" Text='<%#Bind("propietario") %>'></asp:TextBox>
<asp:Button ID="btnUpdate" runat="server" CommandName="Update" Text="Update" />
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
DataSourceMode="DataSet"
ConnectionString="<%$ ConnectionStrings:Data%>"
SelectCommand="SELECT [idpropiedad],[propietario] FROM [dbo].[Propiedades] WHERE [idpropiedad] = 525293 "
UpdateCommand="update [dbo].[Propiedades] set [idpropiedad]=#idpropiedad,[propietario]=#propietario WHERE [idpropiedad] = 525293">
<SelectParameters>
<%--no need as select command doesn't have parameters --%>
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="idpropiedad" Type="Int32" />
<asp:Parameter Name="propietario" Type="String" Size="1024" />
</UpdateParameters>
</asp:SqlDataSource>
This is my first time using asp.net so pleaseaccept my apologies if this is a dumb question.
I am trying to make a web application that will work on our work sharepoint. the idea is a team of people can select when they are available to call or not and if they are the contact point that day so that people on different floors can see their availability without a line of sight.
i would normally make a basic php script but sharepoint doesnt like php and we cannot reference to external resources on our network.
The issue i have is the table that should be pulling data from the xml is just a blank page... originally it gave an error saying it couldnt find that data field and i realised i needed to use xpath to be more specific... it now doesnt give any error, like its finding the field but doesnt draw it. the code is below:
XML database:
<?xml version="1.0" encoding="utf-8" ?>
<CRM>
<agent>
<id>user1</id>
<name>name</name>
<turret>extension</turret>
<email>email</email>
<status>XXXXX</status>
<contact>N/A</contact>
</agent>
<agent>
<id>user2</id>
<name>Name 2</name>
<turret>extension</turret>
<email>email</email>
<status>XXXXX</status>
<contact>N/A</contact>
</agent>
<agent>
<id>user3</id>
<name>Name 3</name>
<turret>Extension Number</turret>
<email>email address</email>
<status>XXXXX</status>
<contact>N/A</contact>
</agent>
</CRM>
and the datagrid that should be pulling that data is here:
<%# Page Language="vb" AutoEventWireup="false" CodeBehind="CSTvisibility.aspx.vb" Inherits="CRM_availabilty.CSTvisibility" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:XmlDataSource ID="data" runat="server" DataFile="~/crmdata.xml" XPath="/agent"></asp:XmlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BorderStyle="Ridge" DataSourceID="data">
<Columns>
<asp:BoundField DataField="name" HeaderText="CRM Agent" />
<asp:BoundField DataField="turret" HeaderText="Turret" />
<asp:BoundField DataField="email" HeaderText="Email" />
<asp:BoundField DataField="status" HeaderText="Available" />
<asp:BoundField DataField="contact" HeaderText="Contact Point" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Switch to TemplateField instead of BoundField. Then you have access to the XPath.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataSourceID="data">
<Columns>
<asp:TemplateField HeaderText="CRM Agent">
<ItemTemplate>
<%# XPath("name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Turret">
<ItemTemplate>
<%# XPath("turret") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<%# XPath("email") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The XPath in the XmlDataSource must be XPath="CRM/agent"
I have the code below.onClientClick event of the linkbutton showVlaues javascript function is executed. I tried to trace the code in the debug mode and when I click on the link button, the debuuger control is tranferred to the showvalues function and then it goes to the code behind and goes to page load event of the application and then it goes again to the showvalues function, I am not sure why it does that, but in debug mode, I can see that it goes to both the $get lines and when I tried to see the value of dataitems, it dataitems is not defined in current context and it changes the value of showValues. Is their any way I can avoid it that control does not go to showvalues function again. I want it to be executed only once when I click on the link button.
any help will be appreciated.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function showValues(IDValue, timeValue, minValue){
var dataItems = $get('<%= PanelBar1.Items[0].Items[0].FindControl ("Grid_IDPicker").ClientID %>')
var lbl_ID = $get('<%= PanelBar1.Items[0].Items[0].FindControl("lbl_ID").ClientID %>');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display.">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" SortExpression="id" />
<asp:BoundField DataField="time" HeaderText="time" SortExpression="time" />
<asp:BoundField DataField="min" HeaderText="min" SortExpression="min" />
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkClick" OnClientClick='<%#String.Format("return showValues({0},'{1}','{2}')", Eval("id"),Eval("time"),Eval("min")) %>' runat="server"> <%# Eval("id") %></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString1 %>"
ProviderName="<%$ ConnectionStrings:TestDBConnectionString1.ProviderName %>"
SelectCommand="SELECT [id], [time], [min] FROM [name]"></asp:SqlDataSource>
</form>
</body>
</html>
I'm trying to filter a gridview using a dropdown, but it appears that the dropdown value that is getting selected isn't making it to my SqlDataSource control. (I'm new to asp.net and this is a tutorial I'm working on.)
When I remove the SelectParameters section and plug one a valid LastName into the where clause of the gridview's select statement, I get a filtered gridview as I would expect, but it doesn't work when I'm selecting a name from the dropdown.
This may be a VS version thing. I'm using VS 2010 (w/.Net 3.5) where the book uses VS 2008.
The code:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="SqlDataSourceParameters_3.aspx.cs" Inherits="SqlDataSourceWizard" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:SqlDataSource ID="CustomersDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString %>"
SelectCommand="SELECT [FirstName], [LastName], [EmailAddress], [ModifiedDate] FROM [Person].[Contact] WHERE ([LastName] = #LastName)">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1"
Name="LastName" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:GridView ID="CustomerGridView" runat="server" AutoGenerateColumns="False"
DataSourceID="CustomersDataSource" EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress"
SortExpression="EmailAddress" />
<asp:BoundField DataField="ModifiedDate" HeaderText="ModifiedDate"
SortExpression="ModifiedDate" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="StaffDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString2 %>"
SelectCommand="SELECT DISTINCT [LastName] FROM [Person].[Contact] ORDER BY 1"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="StaffDataSource" DataTextField="LastName"
DataValueField="LastName">
</asp:DropDownList>
</form>
</body>
</html>
Maybe I am missing something here but what is causing a postback? I do not see a button nor do I see the dropdown's autopostback property set to true. Is your code behind doing something (like setting the default value of the dropdown)?
iam using ajaxtoolkit in asp.net 3.5, using filter texbox extender control
<%# Page Language="C#" %>
<%# Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit"
Assembly="AjaxControlToolkit" %>
<!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>Show Filtered TextBox</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Label
id="lblNumeric"
Text="Enter a Number:"
AssociatedControlID="txtNumeric"
Runat="server" />
<br />
<asp:TextBox
id="txtNumeric"
Runat="server" />
<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txtNumeric" FilterType="Numbers">
</ajaxToolkit:FilteredTextBoxExtender>
<br /><br />
<asp:Label
id="lblProductCode"
Text="Enter a Product Code:"
AssociatedControlID="txtProductCode"
Runat="server" />
<br />
<asp:TextBox
id="txtProductCode"
Runat="server" />
<br />
(A product code can contain only lower-case characters,
![enter image description here][1] underscores, exclamation marks, and no spaces)
</div>
</form>
</body>
</html>
iam using extender control..witfiltertype as numbers..but in doesnt works at runtime,, it accepts all characters..
any help would be appreciated
You are trying to make your code more complex. Actually the FilterTypeExtender is very easy to use. Follow this way. [Note: Close the appropriate controls properly.]
<asp:TextBox ID="txtExperienceYears" runat="server" Width="223px" MaxLength="2"></asp:TextBox>
<%-- Now add the FilterTypeExtender below --%>
<asp:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txtExperienceYears" FilterType="Numbers"></asp:FilteredTextBoxExtender>