|
I have a tab control which is AJAX enabled, and each tab has a user control. Each user control has a GridView bound to a set of Textbox controls and validators associated with it. Validation is executed on one user control and this navigates to the second tab which binds the grid (under the other user control) to a new set of Textbox controls and validators. Once again, on the event handler of a click event, I perform validation.
Here's the problem: The Page.Validators collection object has all the validators from the 1st and 2nd user controls. I only want validators validating a grid from a single user control. I could set the .Visible property to false on a user control I don't want to validate, but that still leaves an issue with checking the Page.Validators collection object. I have to be able to navigate (set focus) on the textbox control associated with the invalid Validator. Somehow, I would like to clear out the validators from all but the one active user control. Any suggestions?(Remember, I have AJAX enabled)...thank you.
|
|
|
|
|
You can specify validation groups, then you can validate just the group you're interested in. I do this with an AJAX enabled page where there are several groups all visible, and I only want to validate one. Once you specify the validation groups in your ASPX, you can do this in your javascript:
Page_ClientValidate("ValidationGroupName");
if (Page_IsValid)
{
Proceed
}
The Page_ClientValidate call will handle showing your validators, but you need to do the check before you proceed with the AJAX call.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Thank you. However, I figured out an alternate solution to my problem. Since I'm only viewing one grid at a time, I didn't think to just bind a set of blank data to the other grid I tabbed away from. That way, the Page clears out the validators no longer there for the old grid. I just have to remember to rebind the data back when I go back to that tab. I tried what you suggested. But, when there is an invalid control, it become difficult when I want to "SetFocus" on that control because I have to look through all the Page.Validators and figure out which ones were for which grid. Thanks anyway.
|
|
|
|
|
Hi all.
I hope one of ya guys can cast a light over what is going on here.. When calling GetUser in MembershipProvider I lose the user object in what can best be illustrated with this code snippet:
MembershipUser user = MembershipProvider.GetUser(UserName, true);
Of course it's not as simple but let me elaborate.
I use Firebird as database and hence I use the Fb providers (FbMembershipProvider etc.) but due to design faults or my machine setup I've had to make my own implementations. My own custom providers are really simple.Here are some code snippets that should explain how they works:
// PrimeMembership.cs
// FbMembershipProvider doesn't read from web.config!?
public class PrimeMembership : FbMembershipProvider
{
public void ForceInitialize()
{
if (base.ApplicationName != "PrimeBooking")
{
NameValueCollection config = new NameValueCollection();
config.Add("connectionStringName", "Membership");
config.Add("enablePasswordRetrieval", "false");
...
base.Initialize("FirebirdMembershipProvider", config);
}
}
}
//PrimeBookingUser.cs
public interface IPrimeBookingUser
{
int ArtistID { get; }
UserType Role { get; }
}
/// <summary>
/// Same as <see cref="MembershipUser"/>MembershipUser but with
/// Artist ID and Role
/// </summary>
public sealed class PrimeBookingUser : MembershipUser, IPrimeBookingUser
{
...
/// <summary>
/// Constructor
/// </summary>
public PrimeBookingUser()
{
DataAccessLayerManager dal = DataAccessLayerManager.GetDALManager();
_artistID = (int)dal.OpenQueryScalar("GetArtistID", Parameter.GetParameter("MembershipGUID", this.ProviderUserKey,
System.Data.DbType.Guid, System.Data.ParameterDirection.Input));
}
}
Now that you have seen my custom implementation let's go to the code that causes the trouble. I have made a simple caching class called CacheManager (it's not really a manager but the name will hunt me until I make it a full blown manager) that uses the Cache class from ASP.NET.
1 /// <summary>
2 /// Gets the user.
3 /// </summary>
4 /// <returns>A user class that inherit from <see cref="MembershipUser">MembershipUser</see></returns>
5 public User GetUser() where User : MembershipUser
6 {
7 // First check to see if an instance of this user already exists in the Cache.
8 User cachedContact;
9
10 cachedContact = _context.Cache[_context.User.Identity.Name] as User;
11
12 if (null == cachedContact || cachedContact.ProviderUserKey == null)
13 {
14 if (_context.User.Identity.IsAuthenticated)
15 {
16 PrimeMembership provider = new PrimeMembership();
17 // force membership provider to initialize
18 provider.ForceInitialize();
19 // cachedContact is always null
20 cachedContact = provider.GetUser(_context.User.Identity.Name, true) as User;
21 }
22 else
23 {
24 FormsAuthentication.RedirectToLoginPage("msg=Du har været inaktiv i for lang "
25 + "tid. Log venligst på igen.");
26 }
27 }
28 return cachedContact;
29 }
Line 20 is the trouble maker. I have debugged the source code of FbMembershipProvider (the good thing of open-source) and it returns the user just fine. I don't know why I loose the reference but maybe it has to do with that the constructor of PrimeBookingUser is never called?
Anyway, I'll appreciate any help - I know this is a long post! Regards, Jon.
If the world should blow itself up, the last audible voice would be that of an expert saying it can't be done - Peter Ustinov
|
|
|
|
|
floppy_Bop wrote: 19 // cachedContact is always null
20 cachedContact = provider.GetUser(_context.User.Identity.Name, true) as User;
Looks like you are casting a parent object to a derived type. Which type do you create in the GetUser method of the provider?
|
|
|
|
|
Yes you're right. GetUser returns MembershipUser. Is it possible to do that? I don't know too much about the underlaying MSIL but in my logic the parent object structure should fit nicely in the derived one. If not - how can I cast MembershipUser to my custom MembershipUser?
Thanks in advance!
If the world should blow itself up, the last audible voice would be that of an expert saying it can't be done - Peter Ustinov
|
|
|
|
|
Basically, in C# you can cast a derived object to its base class, but not all instances of the base type can be cast to a derived child even the structure of the base type fits nicely in the derived one. Here, in the GetUser method of your custom membership provider if you create and return an object of the MembershipUser(the base type) then in the client code you cannot cast it to your custom membership user class (the derived one). However, if you create an object of your custom membership user in the GetUser method then the casting in the client code is fine though you use the base class MembershipUser(base) as the return type. It works because the real type of the returned object of the method is still your custom membership user.
+ So, in your custom provider you should override the GetUser method and return a real object of your custom membership user class.
+ Another option is that in the client code you instead of using casting, you can create an object of your custom membership user and copy all properties from the returned object(base type) to the new object. However, the first option is a better choice.
|
|
|
|
|
minhpc_bk wrote: + Another option is that in the client code you instead of using casting, you can create an object of your custom membership user and copy all properties from the returned object(base type) to the new object.
I guess you mean MemberwiseClone. I have to use that from inside my custom MembershipUser, so both methods will requirer me to override either FbMembershipProvider or MembershipUser which is something I was hoping not to do. It pains me enough that I had to make my stupid forceInitialize implementation. I've found this code snippet:
public static object ShallowClone(object obj)<br />
{<br />
return typeof(object).GetMethod("MemberwiseClone", System.Reflection.BindingFlags.NonPublic<br />
| System.Reflection.BindingFlags.Instance).Invoke(obj, new object[0]);<br />
} That I hope will do the job.. But thanks a lot - I would never have found out by my self.
Cheers, Jon.
If the world should blow itself up, the last audible voice would be that of an expert saying it can't be done - Peter Ustinov
|
|
|
|
|
My asp.net application has web.config file. I have some configuration sections that i want to place in another file say web2.config.
How can i use multiple configuratioin files in asp.net?
Someone told me to use the 'file' attribute. How to do that?
|
|
|
|
|
|
Thanks.
I found a lot of links on google and visted all of them. In one looked at the file attribute of appSettings that is used to refer appSettings stored in external file. I have my own custom settings in my custom sections. How to refer those?
|
|
|
|
|
Sir,
If I want to check the user not to fill numbers in character-required controls and characters in number-required controls.
Waiting for Reply
Durgesh
Durgesh Kumar Mishra
|
|
|
|
|
check it
Or if your really too lazy to find it yourself: (note these have limitations and I haven't checked for accuracy)
chars only: ^[a-zA-Z]*$
numbers only: ^[0-9]*$
|
|
|
|
|
alpha: ^\D+$
numbers: ^\d+$
|
|
|
|
|
Thanks Sir for ur co-operation. Thanks heartly.
Durgesh Kumar Mishra
|
|
|
|
|
Sir,
I've used required field validator and set all the properties and it works better at the time of post generated by 'Submit' button but if I click on my side-menu link buttonslike "Home" this field checks me and demands to fill these fields first. How I get rid of it. I want it should work with Submit button but let me go to other pages when I click on other Links.
Thanks and waiting
Durgesh
Durgesh Kumar Mishra
|
|
|
|
|
Check out the ValidationGroup property (both on validator and submit button)
|
|
|
|
|
Hi All...
I have a form that adds users to the application, I use a submit button to add with event onClick_Button, when I insert all data in fields and then press enter, it does not add until I click on to the submit button, I want to know how to fire the onClick_button event when I click enter button,,
Thanks alot...
Nour Abdel-Salam
|
|
|
|
|
This is probably to do with how browsers handle submit buttons and forms. If there is only one submit button (and I mean an input with type="submit" on the client, whatever server-side controls you have) this should no problem, but if the button is rendered as type="button" or there is more than one this won't happen (although if theres more than one I think it fires the first....could be wrong).
Either the submit button isn't really rendering as a proper submit or you have more than one on your page.
|
|
|
|
|
Thanx for your response
My form has only 2 textboxes and a submit button (type submit)...
When I press enter, it does not insert the data, until i press the button by mouse...
regards
|
|
|
|
|
Can you post the markup code?
|
|
|
|
|
web.config is as under:
<configuration>
<configsections>
<appsettings file="objectAConfiguration">
web2.config is as under:
<configuration>
<configsections>
<objectaconfiguration
="" property1="70.00" property2="2.5" startingcost="257.20">
ObjectAConfiguration class is as under:
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Xml;
namespace MyApp
{
[Serializable]
public class ObjectAConfiguration:ConfigurationSection
{
#region Properties
[ConfigurationProperty("property1", DefaultValue = 60.00F)]
public float Property1
{
get { return (float)this["property1"]; }
set { this["property1"] = value; }
}
[ConfigurationProperty("property2", DefaultValue = 1.50F)]
public float Property2
{
get { return (float)this["property2"]; }
set { this["property2"] = value; }
}
#endregion
}
}
Problem Area is bellow:
MyApp.ObjectAConfiguration objAConf= (MyApp.ObjectAConfiguration)ConfigurationManager.GetSection("objectAConfiguration");
The above did not find the web2.config file and thus objectASection section.
Thanks.
|
|
|
|
|
Use the "Ignore HTML" option when posting markup code.
---
Year happy = new Year(2007);
|
|
|
|
|
Sorry! the site did not display my contents entirly and correctly.
web.config is as under:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="objectXConfiguration"
type="MyApp.ObjectXConfiguration, MyApp"
allowLocation="true"
allowDefinition="Everywhere"
/>
<section
name="objectZConfiguration"
type="MyApp.ObjectZConfiguration, MyApp"
allowLocation="true"
allowDefinition="Everywhere"
/>
</configSections>
<appSettings file="objectAConfiguration">
</configuration>
web2.config is as under:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="objectAConfiguration" type="MyApp.ObjectAConfiguration, MyApp"
allowLocation="true"
allowDefinition="Everywhere"
/>
</configSections>
<objectAConfiguration
property1="70.00"
property2="2.5"
startingCost="257.20"
/>
</configuration>
ObjectAConfiguration class is as under:
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Xml;
namespace MyApp
{
[Serializable]
public class ObjectAConfiguration:ConfigurationSection
{
#region Properties
[ConfigurationProperty("property1", DefaultValue = 60.00F)]
public float Property1
{
get { return (float)this["property1"]; }
set { this["property1"] = value; }
}
[ConfigurationProperty("property2", DefaultValue = 1.50F)]
public float Property2
{
get { return (float)this["property2"]; }
set { this["property2"] = value; }
}
#endregion
}
}
Problem Area is bellow:
MyApp.ObjectAConfiguration objAConf= (MyApp.ObjectAConfiguration)ConfigurationManager.GetSection("objectAConfiguration");
The above did not find the web2.config file and thus objectASection section.
Thanks.
|
|
|
|
|
Imports System.Data
Imports System.Data.OleDb
Partial Class Links
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("ID") = Nothing Then
Response.Redirect("default.aspx?flag=2")
End If
Dim conn As New OleDbConnection
Dim cm As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
HyperLink1.Enabled = False
HyperLink2.Enabled = False
HyperLink3.Enabled = False
Try
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Hosting;Data Source=JICC"
conn.Open()
cm.Connection = conn
cm.CommandText = "Select * From users where u_id=" & Session("id") & " "
dr = cm.ExecuteReader()
If dr.HasRows Then
Do While dr.Read
If dr.GetValue(7) = 1 Then
HyperLink1.Enabled = True
End If
If dr.GetValue(8) = 1 Then
HyperLink2.Enabled = True
End If
If dr.GetValue(9) = 1 Then
HyperLink3.Enabled = True
End If
Loop
dr.Close()
conn.Close()
Else
dr.Close()
conn.Close()
End If
Catch ex As Exception
Response.Write(Err.Description)
End Try
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As New OleDbConnection
Dim cm As New OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader
Try
conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Hosting;Data Source=JICC"
conn.Open()
cm.Connection = conn
cm.CommandText = "Select * From types where t_name='" & TextBox1.Text & "' "
dr = cm.ExecuteReader()
If dr.HasRows Then
Do While dr.Read
Label1.Text = " نوع العقار موجود سابقاُ"
Label1.Visible = True
Loop
Else
Dim cm1 As New OleDb.OleDbCommand
cm1.Connection = conn
cm1.CommandText = "insert into types(T_Name) values('" & CStr(TextBox1.Text) & "') "
cm1.ExecuteNonQuery()
Label1.Text = "تمت الإضافة"
Label1.Visible = True
TextBox1.Text = ""
End If
dr.Close()
conn.Close()
Catch ex As Exception
Response.Write(Err.Description)
End Try
End Sub
End Class
|
|
|
|