|
its so confusing?? Sorry i didnt get anything... can you clearly write down in steps.. that will be more helpful ?? where to keep which part ??
suchita
modified on Monday, May 17, 2010 2:26 PM
|
|
|
|
|
As i assume that you want textbox1 and textbox2 to get their values during an event in your usercontrol (ascx file), you have to follow Mark Nischalkes instructions.
For example:
In your ascx file, you can set the Text Property of your textbox1 control (which is inside the ascx) easily by using:
TextBox1.Text = "xy";
This is pretty simple. In addition, you want to set the text of another TextBox (Textbox2)- which lives inside the aspx Page. This is more complex.
You have to define an event/delegate in your .ascx file (usercontrol), which is subscribed by your page class (.aspx.cs) during page load and called when you set the textbox1.text property.
This is the server-side solution. Another possibility would be to use javascript.
I'm posting some example code now, which is not a 100% answer to your question, but it should help you out. I cannot modify this code more due to time restrictions:
Define this delegate (maybe in a seperate file somewhere in your
usercontrols namespace):
public delegate void OnSelectDelegate(string text);
In your Usercontrol:
public partial class MyUserControl: ....
{
public OnSelectDelegate OnSelect;
private void SetText(string text)
{
TextBox1.Text = text;
if (OnSelect != null)
OnSelect(text);
}
}
In your aspx Page during page-load:
this.MyUserControl1.OnSelect += new SomeNameSpace.OnSelectDelegate(OnSelect);
Include this method in your aspx:
private void OnSelect(string text)
{
TextBox2.Text = text;
}
Hope i didnt include too many typing mistakes and this helps a bit.
Good Luck
|
|
|
|
|
hey
this.MyUserControl1.OnSelect += new SomeNameSpace.OnSelectDelegate(OnSelect);
hey here MyUserControl1 is the ascx class name or one of the control in ascx file ?
suchita
|
|
|
|
|
I think at this point you should give up and hand over the project to someone else. If this confuses you, you are most certainly over your head.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
can you give some more examples ??
suchita
|
|
|
|
|
mmm! hard to understanding?
let's say that you have an ascx page name Logo.ascx.
Then when you add this ascx to a page named Test.aspx, your ascx User Control is named with ID="Logo1" in the Logo.ascx.cs add this:
public string txt;
private string Text
{
get { return txt; }
set { txt = value; TextBox1.Text = value; }
}
and now you can call the public property of the ascx file! use this in Test.aspx or any page you've added the User Control
protected void Page_Load(object sender, EventArgs e)
{
Logo1.txt = "my text";
TextBox2_GetText.Text = Logo1.txt;
}
good luck
|
|
|
|
|
PunkIsNotDead wrote: good luck
Good luck indeed if anyone uses this
First, never expose a public variable, use proprties to expose them. Otherwise you have no way to validate and control access.
PunkIsNotDead wrote: TextBox1.Text = value;
This is completely backward and unecessary.
You have missed the OP's original request and intent and have added nothing but confusion to the subject.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Ok thanks mark! but that was the first thing that came to mi mind! I'll take and follow your suggestions!
|
|
|
|
|
Hey,
thank you for the reply.
Ya I can do it in page_load. That wasn't a problem but I need this with usercontrol event. Like for example, if you have one button in usercontrol(in .ascx page) and i want all those things in that button click.
Can you tell further about this please??
suchita
|
|
|
|
|
Hey,
I forgot to tell one more thing. I can do this in the button click of the aspx page. But I want my button in user control in ascx page for this and in that button click, i want all those things..
suchita
|
|
|
|
|
Ok! I know what you need! create a class (named ResponseEventArgs) that inherits the EventArgs and add a property named myValue. Like this
public class ResponseEventArgs : EventArgs
{
private String _myValue;
public String MyValue
{
get { return _myValue; }
set { _myValue = value; }
}
}
Then in your ascx user control, add the event and the correct delegate
public delegate void ResponseEventHandler(object sender, ResponseEventArgs d);
public event ResponseEventHandler ResultOfMyText;
here you've added the event ResultOfMyText and the handler ResponseEventHandler. Now in the ascx user control add the event as a virtual function
[Description("Event that fires after button click of user control")]
protected virtual void OnResult_Show(ResponseEventArgs re)
{
if (ResultOfMyText != null)
ResultOfMyText(this, re);
}
Now in button Click event of the user control, add the correct value to MyValue Property
ResponseEventArgs re = new ResponseEventArgs();
re.MyValue = Txt_Value.Text;
OnResult_Show(re);
then when you've added this user control, you'll see that it has a event named ResultOfMyText. Trigger that event, and you'll see that you have a d.MyValue in ResultEventArgs and will execute that event every time that you click on the button inside the user control. I hope this won't be confused
|
|
|
|
|
so just the first part is in aspx right ??
public class ResponseEventArgs : EventArgs{
private String _myValue;
public String MyValue
{
get
{ return _myValue; }
set { _myValue = value; }
}}
suchita
|
|
|
|
|
have you create a class with name ResponseEventArgs.cs??
the content of that class should have
private String _myValue;
public String MyValue
{
get
{ return _myValue; }
set { _myValue = value; }
}}
if you've created! then look where it is! for example, if I've created the class in a folder named "Classes", I have to reference it like Classes.ResponseEventArgs
Ahh and the first part is from the ResponseEventArgs.cs class! the other parts are from the ascx userControl. And in the aspx page you will see the event ResultOfMyText and when you've triggered, it would look like this
protected void ResultOfMyText(object sender, ResponseEventArgs d)
{
String response = d.MyValue;
}
modified on Wednesday, May 19, 2010 4:28 PM
|
|
|
|
|
hey i still couldn't get out of it. Let me put down what all i did.
I have one button and a textbox in usercontrol1.ascx page.
the code inside this page is shown as:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Globalization;
using System.Text;
namespace ProjectRequestTest
{
public delegate void ResponseEventHandler(object sender, ResponseEventArgs d);
public partial class usercontrol1 : System.Web.UI.UserControl
{
public event ResponseEventHandler ResultOfMyText;
protected void Page_Load(object sender, EventArgs e)
{
}
[Description("Event that fires after button click of user control")]
protected virtual void OnResult_Show(ResponseEventArgs re)
{
if (ResultOfMyText != null)
ResultOfMyText(this, re);
}
protected void Button1_Click(object sender, EventArgs e)
{
ResponseEventArgs re = new ResponseEventArgs();
re.MyValue = TextBox1.Text;//You need a textbox named Txt_ValueOnResult_Show(re);
OnResult_Show(re);
}
}
}
now the ResponseEventArgs.cs class has code like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ProjectRequestTest
{
public class ResponseEventArgs : EventArgs
{
private String _myValue;
public String MyValue
{
get
{
return _myValue;
}
set
{
_myValue = value;
}
}
}
}
now for usercontrol.aspx page, i have one textbox and that usercontrol from ascx page. the code behind in this page is :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ProjectRequestTest
{
public partial class usercontrol : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ResultOfMyText(object sender, ResponseEventArgs d)
{
TextBox1.Text = d.MyValue;
}
}
}
but when i click the button, the textbox of aspx page is still not showing the value ??
What could have gone wrong ???
suchita
|
|
|
|
|
Maybe it is showing! all the code is correct! i'm sure that if you put a breakpoint,
the d.MyValue is
the textbox.Text of user control.
I've copied the text you have written! and it works
for me! that simple! Have you added the event
in the aspx page??
<%----%>
< uc1:TestUserControl ID="UsrCtr_Test" runat="server"
OnResultOfMyText="ResultOfUserControlTextBox" / >
to codebehind
protected void ResultOfUserControlTextBox(object sender, ResponseEventArgs d)
{
Txt_MyTextBox.Text = d.MyValue;
}
good luck! I hope you finish with this
|
|
|
|
|
Thank you very much..
suchita
|
|
|
|
|
Ok no problem! that's why we are here!
|
|
|
|
|
Is there a way to create an export to excel option on the website that creates tabs in excel with the appropriate data.
Similar to writing the gridview content to excel.
|
|
|
|
|
pls how do i prevent the page from seting focust to top each time a combo is selected?
thank you.
modified on Monday, May 17, 2010 10:41 AM
|
|
|
|
|
|
This will only happen if you have AutoPostBack = true in your combo box, You can either disable it, or if it is required then use the 'Update Panel' and put the combobox inside the panel so that it will do the partial post back and you will have the same scroll bar position even after the post back.
|
|
|
|
|
I ran into this issue yesterday and was able to stop it with this javascript snippet - you dont' call it anywhere, just post it on page like a normal js function:
<br />
window.scrollTo = function( x,y ) <br />
{<br />
return true;<br />
}<br />
Hope this helps.
|
|
|
|
|
I have a scalar valued function named dbo.getname()
When i am writing the following query in the code behind..,
(Text visualizer)
-----------------
SELECT DISTINCT convert(varchar,TRequisition.Date,103) AS Date,
TRequisition.RequisitionID AS ReqNo, TPatient.Name AS Patient,
TRefund.RefundValue, TRefund.Reason AS RefundReason,(dbo.getname(TRequisition.UserID))
AS Operator FROM TRequisition INNER JOIN TPatient ON
TRequisition.PatientID = TPatient.PatientID
INNER JOIN TRefund ON TRequisition.RequisitionID = TRefund.RequisitionID
AND TRequisition.RequisitionID BETWEEN @rangefrom AND @rangeto
order by TRequisition.RequisitionID.
i am getting the following exception:
Cannot find either column "dbo" or the user-defined function or aggregate "dbo.getname", or the name is ambiguous.
help me to solve this.
thanks.
|
|
|
|
|
This is not an ASP.NET question, it is database.
Have you made sure the function exists, is spelled correctly, the correct case, and exists in the dbo schema?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
You need to first try simple query for checking
whether the function getname() exists under dbo or not.
select dbo.getname(12);
If this query fails then the function getname()
does not exists under dbo namespace. It might
exists under db_owner or some another namespace.
Just traverse to that function in sql server
management studio and you will get the exact namespace
of that function.
And please post database related queries in "General Database" section.
Hope this will help!
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|