|
Hello,
I am creating a custom control which uses TextBoxes and Required field validator. I am using INamingContainer in my custom control.
When I use the control in a page I get an error:
"The ControlToValidate property of 'rfvEmail' cannot be blank. "
I have no idea why I am getting this error. It is like I did not referenced the rfvEmail.ControlToValidate. But I did.
I tried everything I could think off but had no luck.
Could somebody help me out?
Here is my code:
Public Class MyControl
Inherits WebControl
Implements INamingContainer
Private WithEvents tbEmail As New WebControls.TextBox
Private WithEvents rfvEmail As New WebControls.RequiredFieldValidator
Private Sub tbEmail_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles tbEmail.Init
tbEmail.Width = Unit.Pixel(200)
End Sub
Private Sub rfvEmail_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles rfvEmail.Init
.ControlToValidate = tbEmail.ID ' ???????? ERROR ?????????
.Display = ValidatorDisplay.Dynamic
.ErrorMessage = "Required Field"
End Sub
Protected Overrides Sub CreateChildControls()
MyBase.Controls.Add(tbEmail)
MyBase.Controls.Add(rfvEmail)
MyBase.CreateChildControls()
Me.ChildControlsCreated = True
End Sub
End Class
Thank You Very Much,
Miguel
|
|
|
|
|
You have not set the ID for the TextBox Control
|
|
|
|
|
Hi,
I am lost but does not "Implements INamingContainer" does that?
Thanks,
Miguel
|
|
|
|
|
Set the ControlToValidate property after you have added the text box to the page.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
Sorry to ask a very basic question probably...
I am currently writing a project in Visual Studio 2005 with vb as language...
I have put a button one my webpage that should lead the user to a second webpage where he can enter data in a form which should be used on the first webpage...
I cannot seem to find how this is done in ASP.NET ?
So when the user clicks the "Add appointment" button he should be taken to another page where he enters all the needed data then pushes the "OK" button. The data is then saved and the user taken back to the first page.
Before i have managed to do so by using Panels en enabling / disabling them to let the user view different forms but my pages seem to get too big...
can anyone lead me to the good way ?
thanx, Olivier
|
|
|
|
|
10 Page 1: Load data from database
20 Page 2: User enters appointment data, save to database, GOTO 10
only two letters away from being an asset
|
|
|
|
|
Olivier,
If I understand your question correctly, you need to create an even handler for your button, and write this code within it:
Server.Transfer("~/SomePath/SomePage.aspx");
Also, this can be doe by this line of code:
Response.Redirect("~/SomePath/SomePage.aspx");
Sorry my code is in C#
You can create an event handler for your button by simply double clicking the button in the designer view.
I hope this helps. Let me know if you need more help
Nila
|
|
|
|
|
Ok! thanx... think that works! i only needed to remove the semicolon to translate from c# to vb
but.... i let the user fill in an inputfield on this second page.. then he clicks OK to go back to the first page...
now i want to read the value filled in on the second page... In PHP you can pass these variables on the url... in vb you can say page2.inputfield etc...
thank you very much for your help!
Olivier
|
|
|
|
|
Hi Olivier,
There are number of ways in which you can accomplish this... you can store your variables as session objects:
Session["myData"] = _myLocalVariable;
Then retrieve it from any other page:
String someString = (Session["myData"]).ToString();
Once again, this is in C#, just make sure you destroy that session after you are done with it (I usually give it a life of minutes).
Let me know if you have any issues
Nila
|
|
|
|
|
thank you, i will try it when i get home :->
your help is very much apreciated !
|
|
|
|
|
Hi Nila,
That works very well...
Is it possible to have the main page open and to create a small pop-up window when the user clicks a certain button. In this small pop-up window he/she should then enter some data and push the OK button which closes the pop-up window and updates the main page ?
Sorry, keep asking questions... but i am discovering the possibilities of ASP.NET !
thank you,
Olivier
|
|
|
|
|
Sure you can! I will send you some code samples tomorrow morning... I gotta go to bed now
I totally know the feeling; with .Net the discovery does not end!!
Nila
|
|
|
|
|
At this point, you would have two pages; the main page (with the pop-up button and all) and the pop-up page (where you store your session variables, and have close button).
STEP1:
In your main page, drag and drop either an HTML button or an asp control that doesn't trigger a post back, such as a label. If you want to use the HTML button, make sure you give it a proper ID and runat="server". Once you did that, write the below code within your pageload event:
<br />
yourLabel.Attributes.Add("onclick", "window.showModalDialog('/yourPath/popup.aspx', null, 'status:no; dialogWidth:360px; dialogHeight:229px; help:no; scroll:no; menubar:no; resizable:no')");<br />
---OR---
<br />
yourHTMLbutton.Attributes.Add("onclick", "window.showModalDialog('/yourPath/popup.aspx', null, 'status:no; dialogWidth:360px; dialogHeight:229px; help:no; scroll:no; menubar:no; resizable:no')");<br />
VERY IMPORTANT- make sure you put this code here:
<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (!Page.IsPostBack)<br />
{<br />
}<br />
<br />
}<br />
STEP2:
Now, its time for you to write code in your pop-up page. Do all your processing, and then store your result(s) in session object(s):
<br />
Session["yourVariable"] = _someLocalVariable;<br />
Session.Timeout = 10;
Then, create a button on your pop-up page, and write the following code for it:
<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (!Page.IsPostBack)<br />
{<br />
closeButton.Attributes.Add("onclick", "window.close();");<br />
}<br />
<br />
}<br />
STEP3:
The last step is to retrieve the data from pop-up and continue the process in main page:
<br />
_mainPageVariable = (Session["yourVariable"]).ToString();
Again, make sure you type-cast correctly. If _mainPageVariable is an integer, then your code would be something like this:
<br />
_mainPageVariable = Int32.Parse((Session["yourVariable"]).ToString());<br />
Let me know if you need any help understanding my C# gibbrish
Nila
|
|
|
|
|
thanx, i just arrived at home....
i'll give it a try tomorrow, this is real fun... didn't know you could do this, it's like a real win application online
just wondering how the main page could "know" when to refresh his page after the user clicked OK in the popup-window? The OK-button just invokes a close-method ?
have a good weekend,
Olivier
|
|
|
|
|
How the main page knows?? Simple! The modal window (pop-up that refuses to stay in the background) will have to finish executing, then when it is closed the client gives the control back to the Main Page to finish its execution... much like how most common compilers work now adays.
Just out of curiosity, have you ever gotten involved with Microsoft's artificial intelligence framework?
Nila
"...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
|
|
|
|
|
Nila,
your codes works very well... i now get a nice nonresizable popup-window when i click on my asp imagebutton....
But... my imagebutton only should launch the popup window when a record in my gridview is selected..
i could do this i suppose:
- when user selects record in gridview i set a sessionvariable
- in the pageload of the popup i check wether the sessionvariable is set
if not the popup closes directly
if set it stays open
is that the good way ?
thanx and have a good sunday :->
|
|
|
|
|
You can have a MultiView in your pop-up page that displays an alternate View (like an error message) if the session variable for some reason is not set.
If you can afford to do so, stay away from ImageButtons in GridViews! They make your ViewState very big. If I were you, in the GridView I would create a templated field with a hyperlink that would trigger a select event AND upon selection it would store a unique value in a session variable, and that hyperlink would also open the pop up page- just hang in there my newbie! I will get some code examples for you...
Nila
"...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
|
|
|
|
|
Ok Olivier, this is how you can open your pop-up from a GridView, and pass data bound parameter to the pop-up. In your .aspx source, paste the following templated column:
<asp:TemplateField HeaderText="Click on Url to open new window" SortExpression="COLUMN_1">
<ItemTemplate>
<asp:HyperLink ID="yourHyperLink" runat="server" NavigateUrl='<%# Eval("EVENT_ID", "~/yourPath/yourPopUp.aspx?yourSessionVariable={0}") %>'Target="_blank" Text='<%# Bind("COLUMN_1") %>'></asp:HyperLink>
</ItemTemplate>
<HeaderStyle Width="180px" />
</asp:TemplateField>
Note that yourSessionVariable={0} will send the value of the FIRST column to your target page. Now, in your pop-up you will have to first get Request.QueryString["yourSessionVariable"], do type casting as you see necessary. But, you are now sending data via GET method which is not exactly safe
You can play around with all the options that you have, and see what works best!
Nila
"...for that, I will need a large cup of coffee and a brand muffin!" -Samantha Bea
|
|
|
|
|
Here are a set of rules to be a good member. Other members will love you for it:
1. Don't use a descriptive heading to your message/question. Something like "NEED HELP" or "URGENT" should be good enough.
2. Don't ask a specific question. Questions like "How to make a webpage" is fine.
3. Don't try to solve the problem yourself. Many here will do your work for you. Just ask for source code.
4. If/when you get your answer, NEVER say "Thank you" or respond in any way to the person that helped you solve your problem.
Keep these rules in mind, and you will be embraced by this community, and you will become a valued member
|
|
|
|
|
|
Guffa wrote: 6. Use as many smilies as possible to show what you mean.
doh!!! Guilty as charged
|
|
|
|
|
|
How to make my web user control take the dimensions of tablecell...
///
<uc1:endmenucontrol id="EndMenuControl1" runat="server">
////
|
|
|
|
|
Does width="100%" height="100%" not work? or perhaps height="292px" width="200px"?
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
How to create a table with browser page dimensions..
Best Regards
|
|
|
|