|
That article is for datagrid. OP is asking for DataGridView.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
I am having trouble getting my ASP search query string to
look up a field Subcategory and display a list
of matches by first character match.
so when an 'A' is entered as the search character, matches
starting with A only are displayed. The script works
for a total list , but however I modify the where/Like line
to put in the last line , the formatting falls apart,
any help much appreciated.
Thanks Bev
strSQL = "SELECT SubCategory, COUNT(*) AS myCount "_
& "FROM Products " _
& "WHERE SubCategory LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
& "GROUP BY Subcategory " _
& "Order BY Subcategory ;"
(SubCategory LIKE @SubCategory + '%')
|
|
|
|
|
Bev Robins wrote: WHERE SubCategory LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
This will look in any part of subcategory. To get results that starts with search criteria, put the search criteria first and % at the last.
Best wishes,
Navaneeth
|
|
|
|
|
Yes , I know that the search criteria needs to be first,
but I am having difficulty trying to do the correct formatting.
& "WHERE SubCategory LIKE '(% + @SubCategory)" & Replace(strSearch, "'", "''") & "%' " _
Thank you ,
Bev.
|
|
|
|
|
I don't think you need the double quotes logic. You are already building the string like this, '%mysearchstuff%'. Take out the Replace function call.
The problem you may have is if the user enters single or double quotes in the search criteria, then your dynamic SQL would syntactilly fail. Strip single and double quotes out first before building your SQL or use a parameterized query and you won't have to worry about anything.
Cheers,
David
|
|
|
|
|
Hi there
I want to use [Autorize(Roles="admin")] to protect my controller methods but i'm not quite sure how it works. I've set up Form Authentication no problem so without roles it works ok
In my controller I have the following code when thu user logs on but once logged in I want to set the cookie and then only a user with the role 'admin' can access /Test. Can somebody explain where the Roles in [Autorize(Roles="admin")] actually looks for its data? I want it to recognise only 'admin' from currently logged on users but also when they return and get the role data from the cookie. Am I missing something, lacking understanding or just going about it the wrong way?
public ActionResult Authenticate(string username, string password, string rememberMe)
{
var user = userRepository.GetUserByName(username);
if (user != null && user.password.Trim() == password)
{
SetAuthenticationCookie(username);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
username,
DateTime.Now,
DateTime.Now.AddMinutes(50),
true,
roles,
FormsAuthentication.FormsCookiePath);
string hashCookies = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
Response.Cookies.Add(cookie);
return RedirectToAction("index", "Home");
}
else
{
return View("Register");
}
}
[Authorize(Roles = "admin")]
public ActionResult Test()
{
return View("chat");
}
I've got this code in my global.asax:
protected void Application_AuthenticateRequest(object sender, EventArgs e){
if (HttpContext.Current.User != null){
if (HttpContext.Current.User.Identity.IsAuthenticated){
if (HttpContext.Current.User.Identity is FormsIdentity){
FormsIdentity identity = (FormsIdentity)
HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = identity.Ticket;
string[] roles = ticket.UserData.Split(',');
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(identity, roles); }
}
}
}
Thanks very much
|
|
|
|
|
Hi, lets say I have a folder called dogs on my server. Now theres a bunch of different aspx pages in there, and certain users are only allowed to access certain ones(note:each aspx page cannot do its own authentication). Now when someones goes to server/dogs/page3.aspx im going to use url rewriting to send them to my ashx page. The ashx page will then check the logged in users session, see if he has access to the page he tried to see and then output the resulting page.
I have this working fine on a previous project out putting images. But now im worried that outputting it a similair way will "break" the link between the aspx page and its code behind.
So whats the best way to go about this?
Thanks so much
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
Found a solution from a combination of 2 articles.
Heres the code inside ProcessRequest:
string page = "~/Dogs/Page3.aspx";
Page compiledPage = (Page)PageParser.GetCompiledPageInstance(page, context.Server.MapPath(page), context);
compiledPage.ProcessRequest(context);
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
hellow friends
i want to hide only those controle which clikede by user for session only.
this conrole agine disply after session close
friends its urgent....
modified on Saturday, November 28, 2009 6:46 AM
|
|
|
|
|
angle57 wrote: friends its urgent....
This is very rude around here. Answers are given voluntarily and although it may be urgent to you, it isn't to anyone else here.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
you can try this:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["buttonnamevisible"] == "false")
Button1.Visible = false;
else
Button1.Visible = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
Button1.Visible = false;
Session["buttonnamevisible"] = "false";
}
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 21:47pm.
|
|
|
|
|
Thanks a lot, but I did this with session and flag variables.
Aging
Thank you very much for provide good suggestion.
|
|
|
|
|
hi,
i need to transfer a key value from a page to a popup page "on selected index change" of a gridview.
i have used a asp:HyperLinkField, to navigate the url.
i got the page to pop up. I need to pass the key value.
plz help me out......
guys its urgent....
|
|
|
|
|
saurabh8april wrote: guys its urgent....
This is very rude around here. Answers are given voluntarily and although it may be urgent to you, it isn't to anyone else here.
The answer is very simple, but I only answer people who are not rude.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Use Session[""] = your key value in the source page, and get the value in the popup page.
modified 27-May-14 5:11am.
|
|
|
|
|
well i have tried avery possible way i can think, but all failed, when passing the value on index change.....
seems have to find an alternate to do this work
anyway thanks for u replies
|
|
|
|
|
Morning. I'm new to ASP.NET and MVC. I'm basically trying to implement an old Chat Application, which uses CodeBehind into my MVC application called SkyBlueBarmy. However, the kind of errors that I get are listed below.
Basically, I keep playing around with the inherits tag but get a different error each time. Is it possible for me to re-use this application in MVC. If so can somebody please give me some pointers because i'm struggling being new to the syntax, error messages and concept.
Thanks very much
Server Error in '/' Application.
--------------------------------------------------------------------------------
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: 'Chat' is not allowed here because it does not extend class 'System.Web.Mvc.ViewPage'.
Source Error:
Line 1: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" AutoEventWireup="true" CodeBehind="matchchat.aspx.cs" Inherits="Chat" %>
Line 2:
Line 3: <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Source File: /Views/chat/matchchat.aspx Line: 1
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
or if I change Inherits to 'SkyBlueBarmy.View.Chat.matchchat'
Server Error in '/' Application.
--------------------------------------------------------------------------------
The view at '~/Views/chat/matchchat.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The view at '~/Views/chat/matchchat.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[InvalidOperationException: The view at '~/Views/chat/matchchat.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>.]
System.Web.Mvc.WebFormView.Render(ViewContext viewContext, TextWriter writer) +108499
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +278
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +10
System.Web.Mvc.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +251
System.Web.Mvc.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +178
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +399
System.Web.Mvc.Controller.ExecuteCore() +126
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +27
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
I've also changed it to System.Web.Mvc.ViewPage<matchchat> and System.Web.Mvc.ViewPage but have reached the guessing stage without understanding what is happening or if I can achieve it.
matchchat.aspx
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" AutoEventWireup="true" CodeBehind="matchchat.aspx.cs" Inherits="Chat" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
chat
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
function SetScrollPosition()
{
var div = document.getElementById('divMessages');
div.scrollTop = 100000000000;
}
function SetToEnd(txtMessage)
{
if (txtMessage.createTextRange)
{
var fieldRange = txtMessage.createTextRange();
fieldRange.moveStart('character', txtMessage.value.length);
fieldRange.collapse();
fieldRange.select();
}
}
function ReplaceChars()
{
var txt = document.getElementById('txtMessage').value;
var out = "<";
var add = "";
var temp = "" + txt;
while (temp.indexOf(out)>-1)
{
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add +
temp.substring((pos + out.length), temp.length));
}
document.getElementById('txtMessage').value = temp;
}
function LogOutUser(result, context)
{
}
function LogMeOut()
{
LogOutUserCallBack();
}
</script>
<form id="form1" defaultbutton="btnSend" defaultfocus="txtMessage" runat="server" >
<div>
<asp:ScriptManager Id="ScriptManager1" runat="server" EnablePartialRendering="true" />
<asp:Label Id="lblRoomName" Font-Size="18px" runat="server" /><br /><br />
<asp:Label Id="lblRoomId" Visible="false" runat="server" />
<asp:UpdatePanel Id="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlId="Timer1" />
</Triggers>
<ContentTemplate>
<asp:Timer Id="Timer1" Interval="7000" OnTick="Timer1_OnTick" runat="server" />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 500px;">
<div id="divMessages" style="background-color: White; border-color:Black;border-width:1px;border-style:solid;height:300px;width:592px;overflow-y:scroll; font-size: 11px; padding: 4px 4px 4px 4px;" onresize="SetScrollPosition()">
<asp:Literal Id="litMessages" runat="server" />
</div>
</td>
<td> </td>
<td>
<div id="divUsers" style="background-color: White; border-color:Black;border-width:1px;border-style:solid;height:300px;width:150px;overflow-y:scroll; font-size: 11px; padding: 4px 4px 4px 4px;">
<asp:Literal Id="litUsers" runat="server" />
</div>
</td>
</tr>
<tr>
<td colspan="3">
<asp:TextBox Id="txtMessage" onkeyup="ReplaceChars()" onfocus="SetToEnd(this)" runat="server" MaxLength="100" Width="500px" />
<asp:Button Id="btnSend" runat="server" Text="Send" OnClientClick="SetScrollPosition()" OnClick="BtnSend_Click" />
<b>Color:</b> <asp:DropDownList Id="ddlColor" runat="server">
<asp:ListItem Value="Black" Selected="true">Black</asp:ListItem>
<asp:ListItem Value="Blue">Blue</asp:ListItem>
<asp:ListItem Value="Navy">Navy</asp:ListItem>
<asp:ListItem Value="Red">Red</asp:ListItem>
<asp:ListItem Value="Orange">Orange</asp:ListItem>
<asp:ListItem Value="#666666">Gray</asp:ListItem>
<asp:ListItem Value="Green">Green</asp:ListItem>
<asp:ListItem Value="#FF00FF">Pink</asp:ListItem>
</asp:DropDownList>
<asp:Button Id="btnLogOut" Text="Log Out" runat="server"
OnClick="BtnLogOut_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</asp:Content>
matchchat.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Text;
using SkyBlueBarmy.Models;
namespace SkyBlueBarmy.Views.Chat
{
public partial class matchchat : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
private string _callBackStatus;
private SkyBlueBarmyDataContext db = new SkyBlueBarmyDataContext();
Label lblRoomId;
Label lblRoomName;
TextBox txtMessage;
ScriptManager ScriptManager1;
DropDownList ddlColor;
Literal litUsers;
Literal litMessages;
public void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string roomId = (string)Request["roomId"];
lblRoomId.Text = roomId;
this.GetRoomInformation();
this.GetLoggedInUsers();
this.InsertMessage(ConfigurationManager.AppSettings["ChatLoggedInText"] + " " + DateTime.Now.ToString());
this.GetMessages();
string callBackReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "LogOutUser", "");
string logOutUserCallBackScript = "function LogOutUserCallBack(arg, context) { " + callBackReference + "; }";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LogOutUserCallBack", logOutUserCallBackScript, true);
}
}
private void GetRoomInformation()
{
var room = (from r in db.Rooms
where r.roomid == Convert.ToInt32(lblRoomId.Text)
select r).SingleOrDefault();
lblRoomId.Text = room.roomid.ToString();
lblRoomName.Text = room.name;
}
public void BtnSend_Click(object sender, EventArgs e)
{
if (txtMessage.Text.Length > 0)
{
this.InsertMessage(null);
this.GetMessages();
txtMessage.Text = String.Empty;
ScriptManager1.SetFocus(txtMessage.ClientID);
}
}
public void Timer1_OnTick(object sender, EventArgs e)
{
this.GetLoggedInUsers();
this.GetMessages();
if ((string)Session["IsChatroomInFocus"] == null)
ScriptManager1.SetFocus(txtMessage);
}
private void InsertMessage(string text)
{
Message message = new Message();
message.roomid = Convert.ToInt32(lblRoomId.Text);
message.userid = Convert.ToInt32(Session["ChatUserID"]);
if (String.IsNullOrEmpty(text))
{
message.text = txtMessage.Text.Replace("<", "");
message.color = ddlColor.SelectedValue;
}
else
{
message.text = text;
message.color = "gray";
}
message.timestamp = DateTime.Now;
db.Messages.InsertOnSubmit(message);
db.SubmitChanges();
}
private void GetLoggedInUsers()
{
var user = (from u in db.Logged_In_Users
where u.userid == Convert.ToInt32(Session["ChatUserID"])
&& u.roomid == Convert.ToInt32(lblRoomId.Text)
select u).SingleOrDefault();
if (user == null)
{
Logged_In_User loggedInUser = new Logged_In_User();
loggedInUser.userid = Convert.ToInt32(Session["ChatUserID"]);
loggedInUser.roomid = Convert.ToInt32(lblRoomId.Text);
db.Logged_In_Users.InsertOnSubmit(loggedInUser);
db.SubmitChanges();
}
string userIcon;
StringBuilder sb = new StringBuilder();
var loggedInUsers = from l in db.Logged_In_Users
where l.roomid == Convert.ToInt32(lblRoomId.Text)
select l;
foreach (var loggedInUser in loggedInUsers)
{
if (loggedInUser.User.gender.ToString().ToLower() == "m")
userIcon = "<img src='Images/manIcon.gif' style='vertical-align:middle' alt=''> ";
else
userIcon = "<img src='Images/womanIcon.gif' style='vertical-align:middle' alt=''> ";
if (loggedInUser.User.username != (string)Session["ChatUsername"])
sb.Append(userIcon + "<a href=#>" + loggedInUser.User.username + "</a><br>");
else
sb.Append(userIcon + "<b>" + loggedInUser.User.username + "</b><br>");
}
litUsers.Text = sb.ToString();
}
private void GetMessages()
{
var messages = (from m in db.Messages
where m.roomid == Convert.ToInt32(lblRoomId.Text)
orderby m.timestamp descending
select m).Take(20).OrderBy(m => m.timestamp);
if (messages != null)
{
StringBuilder sb = new StringBuilder();
int ctr = 0;
foreach (var message in messages)
{
if (ctr == 0)
{
sb.Append("<div style='padding: 10px;'>");
ctr = 1;
}
else
{
sb.Append("<div style='background-color: #EFEFEF; padding: 10px;'>");
ctr = 0;
}
if (message.User.gender.ToString().ToLower() == "m")
sb.Append("<img src='Images/manIcon.gif' style='vertical-align:middle' alt=''> " + message.text + "</div>");
else
sb.Append("<img src='Images/womanIcon.gif' style='vertical-align:middle' alt=''> " + message.text + "</div>");
}
litMessages.Text = sb.ToString();
}
}
public void BtnLogOut_Click(object sender, EventArgs e)
{
var loggedInUser = (from l in db.Logged_In_Users
where l.userid == Convert.ToInt32(Session["ChatUserID"])
&& l.roomid == Convert.ToInt32(lblRoomId.Text)
select l).SingleOrDefault();
db.Logged_In_Users.DeleteOnSubmit(loggedInUser);
db.SubmitChanges();
this.InsertMessage("Just logged out! " + DateTime.Now.ToString());
Session.RemoveAll();
Session.Abandon();
Response.Redirect("Default.aspx");
}
#region ICallbackEventHandler Members
string System.Web.UI.ICallbackEventHandler.GetCallbackResult()
{
return _callBackStatus;
}
void System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
_callBackStatus = "failed";
var loggedInUser = (from l in db.Logged_In_Users
where l.userid == Convert.ToInt32(Session["ChatUserID"])
&& l.roomid == Convert.ToInt32(lblRoomId.Text)
select l).SingleOrDefault();
db.Logged_In_Users.DeleteOnSubmit(loggedInUser);
db.SubmitChanges();
this.InsertMessage("Just logged out! " + DateTime.Now.ToString());
_callBackStatus = "success";
}
#endregion*/
}
}
|
|
|
|
|
Firstly, there is far too much unnecessary code in your post. Most will just ignore a post like this, not wanting to read through pages of code. State the problem you are having and only post the bit relevant to it. And don't say all of this is relevant, it isn't.
It isn't the inherits tag that is the issue. As it says in the error message your class must be derived from ViewPage, ViewUserControl, or a variant of them.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hai ,
i am the begineer in web development,shall i know how to develope the web page more attractive,i mean what are the combination of colors
we use to backgroud color ,and font color and botton , is there any combination's there? give ur advice and suggesstion's
Thank You....
|
|
|
|
|
fak.kumar wrote: we use to backgroud color ,and font color and botton , is there any combination's there?
Use Free Web Templates They are easy to Use..!
http://lmgtfy.com/?q=Free+Website+Templates[^]
LatestArticle :Log4Net
Why Do Some People Forget To Mark as Answer .If It Helps.
|
|
|
|
|
Hi
I am implementing a discussion board as a phase of my project. When we visit a web site to see replies of a thread, the url of the page is something like http://forums.asp.net/t/1335371.aspx. Could anybody please let me know, what is the meaning of number 1335371 and how it is generated. and please give me a reference to learn more about that kind of website implementation.
Thank You....
|
|
|
|
|
That number probably an id of the thread in the database. You can create such links using url rewriting. There are many articles in web about url rewriting.
MSDN[^]
|
|
|
|
|
Hello,
I would like to know if there is anybody interested in building a P3P framework for ASP.NET.
I read many articles about P3P in ASP.NET dealing with "brute" hardcoded headers sent to the client.
Everyone can do this. However, since P3P is sees by many experts as a key framework in Web 2.0, as privacy becomes an always greater concern for users, I was interested in implementing the whole P3P framework into ASP.NET so anyone can build his custom privacy policy with easy configuration steps, ie. by just editing Web.config and adding proper nodes for P3P, which will result in the generation of correct headers.
I don't have a complete knowledge of the P3P model as defined by W3C, so I was wishing to reunite a group of people who are interested in building a complete open source solution to allow developers using P3P in seconds.
The project could also be ported to Java/JSP in the near future.
I am a 2nd level grade Computer Engineer studend and I'm experienced in C#, VB and ASP.NET.
Thank you for your attention.
|
|
|
|
|
Hi! I am doing a new install of visual studio 2002 enterprise architect. am using xp home with sp3. I have my install discs for Exchange Server 2000,Host Intewgration Server 2000,sql server 2000,Windows 2000 server..all these came with the Visual Studio 2002. The whole idea is to get IIS installed so I can use ASP.Net. Which of these programs install IIS? or should I install IIS as a stand alone app? I also have the microsoft express web development platfrom..may I should port to that? What should I do?
Thanks
andy
|
|
|
|
|
andrew p jones wrote: Which of these programs install IIS
None. It's part of XP Pro, but you need the CD to install it, it's not installed by default. It does not come with XP Home, at all.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|